Skip to main content
Known Participant
October 1, 2012
Answered

Script to move description metadata information into title field

  • October 1, 2012
  • 2 replies
  • 2734 views

I have tried for 2 days (off and on) to try to get Bridge CS6 to copy the information from the Description field to the Title field in the metadata. I can get it into the menu, but nothing happens when I modify other scripts. Any suggestions would be greatly appreciated.

If you want a good laugh, I can post my previous attempts.

This topic has been closed for replies.
Correct answer Paul Riggott

This is one way to copy the information ...

#target bridge  
if( BridgeTalk.appName == "bridge" ) { 
descToTitle = MenuElement.create("command", "Description to Title", "at the end of Tools");
}
descToTitle.onSelect = function () {
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var thumb = app.document.selections;
    for(var s in thumb){
if(thumb.hasMetadata){
        var selectedFile = thumb.spec;
  var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
  var myXmp = myXmpFile.getXMP();
         var Description =  getArrayItems(XMPConst.NS_DC, "description");
        myXmp.deleteProperty(XMPConst.NS_DC, "title");
        myXmp.appendArrayItem(XMPConst.NS_DC, "title", Description, 0, XMPConst.ALIAS_TO_ALT_TEXT);
        myXmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
    }
function getArrayItems(ns, prop){
var arrItem=[];
try{
var items = myXmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(myXmp.getArrayItem(ns, prop, i));
     }
return arrItem;
}catch(e){alert(e +" Line: "+ e.line);}
}
        if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
        myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         } else {
  xmpFile.closeFile();
        }
    }
}
   

2 replies

belindat
Participating Frequently
May 9, 2019

Can you tell me what the process is to save this as a .jsx? I understand which folder it goes into, and I have the code copy/pasted into Script Editor, but that utility doesn't like the copied code and I'm unable to save.

Legend
July 19, 2019

Can you post more information? What operating system? Script Editor on the Mac is for AppleScript, not Adobe Extendscript.

Paul Riggott
Paul RiggottCorrect answer
Inspiring
October 1, 2012

This is one way to copy the information ...

#target bridge  
if( BridgeTalk.appName == "bridge" ) { 
descToTitle = MenuElement.create("command", "Description to Title", "at the end of Tools");
}
descToTitle.onSelect = function () {
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var thumb = app.document.selections;
    for(var s in thumb){
if(thumb.hasMetadata){
        var selectedFile = thumb.spec;
  var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
  var myXmp = myXmpFile.getXMP();
         var Description =  getArrayItems(XMPConst.NS_DC, "description");
        myXmp.deleteProperty(XMPConst.NS_DC, "title");
        myXmp.appendArrayItem(XMPConst.NS_DC, "title", Description, 0, XMPConst.ALIAS_TO_ALT_TEXT);
        myXmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
    }
function getArrayItems(ns, prop){
var arrItem=[];
try{
var items = myXmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(myXmp.getArrayItem(ns, prop, i));
     }
return arrItem;
}catch(e){alert(e +" Line: "+ e.line);}
}
        if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
        myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         } else {
  xmpFile.closeFile();
        }
    }
}
   

pwfasprodAuthor
Known Participant
October 1, 2012

100% What I needed! It worked flawlessly- thank you very much. Now, it will be interesting to compare yours with what I did to see where, exactly, I went wrong.