XMP module in UXP offers JavaScript access to the Adobe XMP Core and XMP Files libraries. This feature is now available in UXP 7.2 with Photoshop 25.0.
Reading through the documentation I have one question. Maybe I missed this, but I wonder how XMP’s File I/O relates to Photoshop’s I/O? It seems to me like in order to access a document’s metadata you call XMP’s file I/O. Let’s assume I have a document open in Photoshop, modifying its contents, let’s say I also want to update its metadata. Would XMP’s file I/O use the file that’s already being worked on by Photoshop or open it again separately?
Yes, passing serialized string to the XMPMeta constructor, modify the content on the object using the methods provided and pass it back as string in batchplay to update
@vinayKumarG
Is it possible to provide working example of this since I am not being able to make it work and couldn’t also find anything in the docs.
What I am trying to do is
Read the XMP data of the currently opened file in PS with batchplay
Modify one of the properties(custom namespace)
Save the XMP data to the currently opened file in PS
I’m try to run the sample batch script from the link that was provided to learn how this works. The sample script is giving 2 errors. The image files in the folder are jpg images that contain XMP metadata.
First error line-
if(file instanceof Entry)
ReferenceError: Entry is not defined
So I removed the if statement to just force it to run on each image file. Then it gives the next error
Second Error Line-
let xmpFile = new XMPFile( file.nativePath, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
can you replace the condition in if to if(file.isFile),
we need this condition to work only on Files and not folders,
Also, the error posted could be caused by any files which doesn’t XMP Metadata,
if you still see the error, you might want to check for any hidden files in that folder.
However, the other error still occurs. See the attached screenshot. It is happening on image files as can be seen in the debugger. I tried image files straight off the camera with the standard camera set metadata. I also tried with images that I added metadata to the copyright and descriptions fields in Photoshop through “file>file info” from the Photoshop menu. So those files have Photoshop XMP metadata added. For both types, it gives this error for all images.
For my own plugins, I always use .isFile to check to see if the entry is a file.
I was trying to test the script exactly “as is” from the Adobe documentation. I just assumed that Adobe had a specific reason for using (file instanceof Entry), but just didn’t know what the reason was.
Honestly , I didn’t realize they were just trying to make sure the entry was a file. The use of (file instanceof Entry) threw me off as I had never seen that before.
Problem with instanceof is that it really must be instance of the class you are testing against. E.g. if you would have 2 classes both with same name class Test then it will return true only for one of them but never both. And sometimes you might want this behavior. But in my experience it had more cons than benefits. The condition failed and it was hard to tell what was instance of what because those classes were identical but not the same
Thanks for the info. I still can’t get the other part of the script to work. I assumed the script in the Adobe documents should work as is, but I still get the second error. I tried reading through the documentation page but it is confusing to me and not even sure what to change in their script.
I don’t need to edit meta data like the Adobe script does. I was just going through that to try to learn how it works, but got stuck because the script doesn’t work as is.
Ultimately, what I need to do seems like it should be simple. I just want to take the metadata from one file and then overwrite the metadata in a different file with that same metadata, unchanged.
@ddbell
errors is because, of the second argument XMPConst.UNKNOWN, you need to pass the type of the file, if you are using jpg files can you try passing XMPConst. FILE_JPEG , also you can refer to other values here XMPConst
Thank you for your help. I ran the script with the 2 modifications and it was successful. It did exactly what it was suppose to do to replace the creator/author metadata.
Now I need to dig further into it tomorrow to see if I can get it to work what I need to actually use it for. Hopefully once I get going on it then it will all start to make sense.