You can store a unique identifier in a Photoshop document using XMP metadata, then check for that identifier whenever the document is opened again.
The approach depends on whether you're using ExtendScript (.jsx) or the newer UXP scripting environment.
As an example this checks the active document and only adds an ID if one doesn't already exist:
#target photoshop
if (app.documents.length > 0) {
if (ExternalObject.AdobeXMPScript === undefined) {
ExternalObject.AdobeXMPScript =
new ExternalObject("lib:AdobeXMPScript");
}
var doc = app.activeDocument;
var ns = "https://example.com/photoshop/id/1.0/";
XMPMeta.registerNamespace(ns, "myid");
var xmp = new XMPMeta(doc.xmpMetadata.rawData);
var existingID = xmp.getProperty(ns, "FileID");
if (existingID) {
alert("Existing document ID: " + existingID);
} else {
var newID = String(new Date().getTime()) +
"-" + String(Math.floor(Math.random() * 1000000000));
xmp.setProperty(ns, "FileID", newID);
doc.xmpMetadata.rawData = xmp.serialize();
alert("New document ID assigned: " + newID);
}
}
One consideration is that Photoshop 27 introduced reported problems with XMP with UXP, so older code examples may not work in newer versions.
If your only requirement is to know whether a file has previously been processed, you could maintain an external record of file identifiers rather than modifying the documents themselves.