Script to add folder name as additional keyword - PROBLEM in keywords are added in quotation marks
Can someone help me modify this Bridge script? I have used scripts to add file and folder names to the metadata description field and I am trying to adapt one of those scripts to add keywords. But when the keywords are added they end up with quotation marks around the result.
"keywords; keywords; keyword3"
I think the reason is that I am not adding new keywords as part of an array but as a string. But I'm having trouble correcting that.
Note that I do not get quotation marks when I use this line of code:
Desc=Desc.toString() + "" + FolderName;
And with the above line, the script adds the keyword but without a separation of space or comma
But when I modify the line to add semicolon and space I get the quotation marks:
Desc=Desc.toString() + "; " + FolderName;
The resulting keywords are like this "apple; testfolder" (in this case apple was an existing keyword that I want to keep and testfolder is the folder containing the selected files.
Here is the code.
//this adds the folder name of selected files but not with space as a second keyword
// added semicolon spacein line 33 but it results in keywords enclosed in quotes
#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "FOLDERName to KEYWORD-33", "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[a].spec;
var FileName = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '') // get file name - not neededfor this script
var FolderName = (decodeURI(selectedFile.parent.name)); //get foldername selected File defined above - i added this line
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, "subject"); //replaced description with subject
for(var i = 1;i <= count;i++)
{
Desc.push(myXmp.getArrayItem(XMPConst.NS_DC, "subject", i)); //replaced description with subject
}
Desc=Desc.toString() + "" + FolderName; //was FileName //adding semi colon and space to string
myXmp.deleteProperty(XMPConst.NS_DC, "subject"); //replaced description with subject
myXmp.appendArrayItem(XMPConst.NS_DC, "subject", Desc, 0, XMPConst.ALIAS_TO_ALT_TEXT); //replaced description with subject
myXmp.setQualifier(XMPConst.NS_DC, "subject[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default"); //replaced description with subject
if (myXmpFile.canPutXMP(myXmp))
{
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
