• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript: Set Bridge Label without having to save

New Here ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

Hello, I have a code below that I use for Bridge labeling the images. I would like to know if code below could be improve to Label the images without having to save the document?


The issue with using below code is the original images doesn't have color profile embed into it. And I would like to keep the original images that way. But if images opened using below code, the images will be saved with the Label together with the color profile which I would like to avoid.

 

At the moment, my only work around is just to copy the original images before it opened by Photoshop. I hope someone could help me improving below code. Thank you in advance.

  // =========== copy original file if use Label ====================
    if (addLabel.value == true) {
      myFile.copy(new File(Prefs.outputFolderPath + "/" + filename));
    }
    openFile(myFile);
  // =========== copy original file if use Label END ====================

function openFile(myFile) {
  // =======================================================
  var idOpn = charIDToTypeID("Opn ");
  var desc69 = new ActionDescriptor();
  var iddontRecord = stringIDToTypeID("dontRecord");
  desc69.putBoolean(iddontRecord, false);
  var idforceNotify = stringIDToTypeID("dontNotify");
  desc69.putBoolean(idforceNotify, true);
  var idnull = charIDToTypeID("null");
  desc69.putPath(idnull, new File(myFile));
  var idDocI = charIDToTypeID("DocI");
  desc69.putInteger(idDocI, 227);
  executeAction(idOpn, desc69, DialogModes.NO);

  ////======================== add label ===================
  if (addLabel.value == true) {
    if (ExternalObject.AdobeXMPScript == undefined)
      ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    xmp.deleteProperty(XMPConst.NS_XMP, "Label");
    xmp.setProperty(XMPConst.NS_XMP, "Label", labelList.selection.text);
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
    app.activeDocument.save();
  }
}
  ////======================== add label END ===============

 

TOPICS
Actions and scripting , macOS , Windows

Views

118

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Sep 09, 2022 Sep 09, 2022

Recently you asked a question in the topic Setting Labels and Ratings from JavaScript, it is strange that you did not notice almost the same code that was suggested @Kukurykus Feb 15, 2021 

 

if (addLabel.value == true) {
	if (ExternalObject.AdobeXMPScript == undefined)
		ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
	var xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE),
		xmp = xmpFile.getXMP();
	xmp.setProperty(XMPConst.NS_XMP, "Label
...

Votes

Translate

Translate
Adobe
LEGEND ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

Try using BridgeTalk and have Bridge set the labels.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

Recently you asked a question in the topic Setting Labels and Ratings from JavaScript, it is strange that you did not notice almost the same code that was suggested @Kukurykus Feb 15, 2021 

 

if (addLabel.value == true) {
	if (ExternalObject.AdobeXMPScript == undefined)
		ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
	var xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE),
		xmp = xmpFile.getXMP();
	xmp.setProperty(XMPConst.NS_XMP, "Label", labelList.selection.text);
	if (xmpFile.canPutXMP(xmp)) xmpFile.putXMP(xmp)
	xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

LATEST

Hello, my deepest apology for my obliviousness. When I posted this thread for the first time, it doesn't show right away. I thought it was being reviewed first by admin until it's approve. Then I tried to comment and asked in the thread that you mentioned, as I mentioned there, I am not the original coder, and even @Kukurykus already posted the answer (which I didn't know that it was the answer I am looking for) I couldn't assemble them together with my code as you did here.

Thank you so ever very much for the help. I tried your code and now it works!

Thank you to @Lumigraphics and @Stephen_A_Marsh as I saw you tried to answer on both of my comment and this thread. Once again, sorry and thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

xmp.setProperty(XMPConst.NS_XMP, "Label", labelList.selection.text);

 

Where is labelList.selection.text defined?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines