Remove commas from Description field & copy to Title field

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

Moderators: xbytor, DavideBarranca, Paul MR

Jaybee

Remove commas from Description field & copy to Title field

Postby Jaybee » Mon Apr 22, 2013 10:11 am

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

Postby Paul MR » Mon Apr 22, 2013 5:30 pm

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


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

Jaybee

Remove commas from Description field & copy to Title field

Postby Jaybee » Tue Apr 23, 2013 7:38 am

Thank you so much Paul, that worked perfectly!

Jaybee


Return to “Adobe Bridge Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest