Skip to main content
Participating Frequently
February 14, 2021
Question

Setting Labels and Ratings from JavaScript

  • February 14, 2021
  • 1 reply
  • 1327 views

I'm wanting to write a couple of JavaScripts to automate my save process. Here is what I would like to do:

For the open document, set the label to "Approved" and SaveAs with a new name

Run an Action to resize to 2048 on the long side, add a watermark. ** This is working through normal actions **

Next, I have to decide if I like the default watermark placement or not, so I deselect it, move it if needed then flatten the image. This is pretty quick if I don't need to move it (CMD-D CMD-E)

Now is where the fun comes in.

Next, I want to change the Label to "Second" then I want to rename it to preferably "filename_web.jpg". I actually have this working in a JavaScript script but it gets renamed to "web_filename.jpg" and I can work with it. However, it's not changing either the rating or the label.

Finally, I have another Action that makes an Instagram version (1080 wide, 1350 high, pads verticals if the aspect ratio isn't 4x5) which is working quite well, but I would like to add:

change the label to "Review" and then save as "ig_filename.jpg" (well I'd like filename_ig.jpg, but...)

 

Anyway, I've got the renaming functional, but it's not changing the label. I don't really care about setting the rating since I've typically done that in Bridge when selecting the photos to post-process. Here is my script:

 

var docRef = app.activeDocument
app.activeDocument.info.label = "Second"
app.activeDocument.info.Label = "Second"
app.activeDocument.info.rating = 3
app.activeDocument.info.Rating = 4

var fileName = "web_" + docRef.name
jpgFile = new File( docRef.path + "/" + fileName )
//jpgFile.info.label = "Second"
jpgSaveOptions = new JPEGSaveOptions()
jpgSaveOptions.embedColorProfile = true
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE
jpgSaveOptions.matte = MatteType.NONE
jpgSaveOptions.quality = 10
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true,Extension.LOWERCASE)

This should work according to the couple of PDFs that I've found. The documents don't list Lable and Rating as available, but they show up in the full dump of the XMP data.

 

I'm trying both capitalized and lowercase versions of the objects since the XMP data shows it capitalized while the documentation shows similar fields as lower case.

 

Surely there has to be a way to set the Label from within Photoshop from a scriptable means.

 

Thanks

 

This topic has been closed for replies.

1 reply

Kukurykus
Legend
February 14, 2021
if (!ExternalObject.AdobeXMPScript)
	ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
(metaData = new XMPMeta()).setProperty(XMPConst.NS_XMP,'Label', 'green')
activeDocument.xmpMetadata.rawData = metaData.serialize()
Participating Frequently
February 14, 2021

This worked great. Thank you very much.

As noted, the text for the Label has to match the string Bridge uses or you get white. Also, I had to explicitly set the rating as well. It did not preserve the rating in the open document. But for now this is working like a charm.

 

I didn't change my action that resizes to 2048 and applies the watermark, but changed my IG action to save the web version, do the resizing for IG and then save the IG version. If I don't have to move the watermark, after the image opens from Adobe Camera Raw, it's:

 

CMD-A
Run the Watermark/Resize Script

CMD-D

CMD-E

Run the Make web versions Script

 

That's going to be a huge improvement to my workflow.

 

Kukurykus
Legend
February 14, 2021

To preserve ratings:

if (documents.length &&
(aD = activeDocument).saved) {
	fle = aD.fullName; if (!ExternalObject.AdobeXMPScript)
		ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript')
	xmp = new XMPFile(fle.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
	(metaData = xmp.getXMP()).setProperty(XMPConst.NS_XMP,'Label', 'green')
	xmp.putXMP(metaData), xmp.closeFile(XMPConst.CLOSE_UPDATE_SAFELY)
}