Adding a function to existing Bridge script
Hello everyone.
I am looking to use a metadata field in InDesign as either a "Live Caption" or a "Text Variable". I found this script that will populate the "Description" field with the file name. That's 90% of my battle. What I also need this to do is remove part of the title in the description field for the Caption/Text Variable. Our file name titles are very strict, and different for different programs. To clarify:
My • Program • the file name actually used.indd
Her • Programs • the file name actually used.indd
His • File Name has • the file name actually used.indd
All that I want to show up in the description field is:
the file name actually used
This script does not put .indd into the description, that's good. But I need to be able to put in MULTIPLE beginning variables to be stripped out. E.g.
My • Program •
Her • Programs •
His • File Name has •
I have very little understanding of adding to this script. I would rather not have 2 scripts for one action. If anyone is able to help, I would appreciate it.
Christian
#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "Add File Name to Description", "at the end of Tools");
}
FT.onSelect = function () {
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs.spec;
var FileName = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
var Desc=[];
var count = myXmp.countArrayItems(XMPConst.NS_DC, "description");
for(var i = 1;i <= count;i++){
Desc.push(myXmp.getArrayItem(XMPConst.NS_DC, "description", i));
}
Desc=Desc.toString() + " " + FileName;
myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.appendArrayItem(XMPConst.NS_DC, "description", Desc, 0, XMPConst.ALIAS_TO_ALT_TEXT);
myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
