# How to get unique document identifier

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083>\
**Category:** Photoshop\
**Tags:** api-feedback\
**Created:** [December 28, 2021, 12:37pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083 "2021-12-28T12:37:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![liuxiao](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/liuxiao/32/1905_2.png) [@liuxiao](https://forums.creativeclouddeveloper.com/u/liuxiao)\
**Post date:** [December 28, 2021, 12:37pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/1 "2021-12-28T12:37:25Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/5/59cd42c383a01089f2748d531726b806cd371f72.png)

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

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 28, 2021, 1:03pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/2 "2021-12-28T13:03:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![liuxiao](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/liuxiao/32/1905_2.png) [@liuxiao](https://forums.creativeclouddeveloper.com/u/liuxiao)\
**Post date:** [December 28, 2021, 2:00pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/3 "2021-12-28T14:00:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 28, 2021, 2:10pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/4 "2021-12-28T14:10:43Z")

</div>

Right…  
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 🤔

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

---

<div class="post-metadata">

**Author:** ![samgannaway](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@samgannaway](https://forums.creativeclouddeveloper.com/u/samgannaway)\
**Post date:** [January 4, 2022, 4:38pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/5 "2022-01-04T16:38:27Z")

</div>

Right, you can get the path to an open document.  
`require('photoshop').app.activeDocument.path`  
[https://www.adobe.io/photoshop/uxp/ps\_reference/classes/document/#path](https://www.adobe.io/photoshop/uxp/ps_reference/classes/document/#path)

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.

---

<div class="post-metadata">

**Author:** ![liuxiao](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/liuxiao/32/1905_2.png) [@liuxiao](https://forums.creativeclouddeveloper.com/u/liuxiao)\
**Post date:** [January 5, 2022, 2:00am UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/6 "2022-01-05T02:00:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![XiaoNing](https://avatars.discourse-cdn.com/v4/letter/x/e19adc/32.png) [@XiaoNing](https://forums.creativeclouddeveloper.com/u/XiaoNing)\
**Post date:** [January 5, 2022, 4:44am UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/7 "2022-01-05T04:44:50Z")

</div>

> [@liuxiao](#):
>
> XMP

I think you can get the `XMPMeta` object like this

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

```

---

<div class="post-metadata">

**Author:** ![liuxiao](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/liuxiao/32/1905_2.png) [@liuxiao](https://forums.creativeclouddeveloper.com/u/liuxiao)\
**Post date:** [January 5, 2022, 7:16am UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/8 "2022-01-05T07:16:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samgannaway](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@samgannaway](https://forums.creativeclouddeveloper.com/u/samgannaway)\
**Post date:** [January 5, 2022, 3:52pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-unique-document-identifier/4083/9 "2022-01-05T15:52:18Z")

</div>

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.
