Remove commas from Description field & copy to Title field

Upload Adobe Bridge Scripts, Download Adobe Bridge Scripts, Support for Individual Adobe Bridge Scripts

Moderators: Tom, Kukurykus

Jaybee

Remove commas from Description field & copy to Title field

Post by Jaybee »

Hi,

I've found a script over on the Adobe Bridge scripting forum that works 100% to copy my Description field to my Title field. My one remaining problem is that I need to get rid of the commas in the Description so the Title field contains no punctuation at all.

I'd be grateful to learn the small part of code that will strip the punctuation. I've tried several things but my coding is ropey to say the least! Grateful for any pointers.

Here's the code that works reliably to copy Description to Title:

Code: Select all#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[s].hasMetadata){
        var selectedFile = thumb[s].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();
        }
    }
}

TIA

Jaybee
Paul MR

Remove commas from Description field & copy to Title field

Post by Paul MR »

You could change ..
Code: Select allvar Description =  getArrayItems(XMPConst.NS_DC, "description");


To...
Code: Select allvar Description =  getArrayItems(XMPConst.NS_DC, "description").toString().replace(/[,'\"\.]/g, "");
Jaybee

Remove commas from Description field & copy to Title field

Post by Jaybee »

Thank you so much Paul, that worked perfectly!

Jaybee