How to get unique document identifier

For the same .psd file, it seems that every time a document is opened, photoshop will reassign an ID to it.

Is there any way to uniquely identify a document, even if it is opened at any time, or transferred to other computers for opening.

Maybe get full path and then get metadata of that file and check if there’s something you could use. Maybe create time or similar.

Just speculating

Yes, we actually do this on cep, but on uxp, I’m not sure if I can do this.
I checked uxp#localFileSystem, I think I can get a path like /path/to/psdfile.psd from the document, but it seems that uxp does not allow loading entry from such a path.

You could access that file if it’s opened via plugin though. Or if it’s not an issue, you could ask for access on your plugin action you want to perform and save the token for future :thinking:

It’s a bit weird Adobe won’t give access even for metadata of open documents :frowning:

Right, you can get the path to an open document.

Yes, the document id is only valid per session. There isn’t unique identifier, but you can add your own (or anything else) via XMP metadata.

Thanks Sam.
Yes we do that in CEP, but can I read and write XMP metadata in UXP? how? seems like there is no
another XMPMeta object in UXP.

I think you can get the XMPMeta object like this

const bp = action.batchPlay;
		const getDocumentXMP = () => {
			return bp(
						_obj: "get",
						_target: {
							_ref: [{ _property: "XMPMetadataAsUTF8" }, { _ref: "document", _enum: "ordinal", _value: "targetEnum" }],
				{ synchronousExecution: true }
		const xmpString = getDocumentXMP();
		const matches = xmpString.match(/<xmpMM:OriginalDocumentID>(.+)<\/xmpMM:OriginalDocumentID>/);

Thanks XiaoNing

After reading your reply, I realized that I should first read the document with Alchemist to see what I can get. if I did, I wouldn’t ask this stupid question

Alchemist is our best friend

Sadly, there is no XMPMeta for UXP (yet). You’ll find a few threads in this forum discussing how to handle it. Put simply, it’s XML. You just have to get and set it wholesale.