Copy link to clipboard
Copied
Hello,
I need to create a process of copying the file name of a jpg to the keywords in Bridge CS6. Ideally I need the script to parse the file name and use the words (not the symbols like "_" or "-") as keywords of the file.
Here's an example:
input
file name: jane_doe.jpg
keywords:
output
file name: jane_doe.jpg
keywords: jane doe
I don't know where to start with this scripting. Any help or advise would be much appreciated! Perhaps you know of a really similar one that i can modify??
Thanks in advance,
Claudia
Please try this on selected files.
...#target bridge
if( BridgeTalk.appName == "bridge" ) {
filebits = MenuElement.create("command", "Add Filename bits to Keywords", "at the end of Tools");
}
filebits.onSelect = function () {
var sels = app.document.selections;
for (var i = 0; i < sels.length; i++){
var md = sels.synchronousMetadata;
var Filename = decodeURI(sels.name);
var nameParts = Filename.split(/-|_|\./);
nameParts.pop();
md.namespace = "http://ns.adobe.com/photoshop/1.0/"
Copy link to clipboard
Copied
Please try this on selected files.
#target bridge
if( BridgeTalk.appName == "bridge" ) {
filebits = MenuElement.create("command", "Add Filename bits to Keywords", "at the end of Tools");
}
filebits.onSelect = function () {
var sels = app.document.selections;
for (var i = 0; i < sels.length; i++){
var md = sels.synchronousMetadata;
var Filename = decodeURI(sels.name);
var nameParts = Filename.split(/-|_|\./);
nameParts.pop();
md.namespace = "http://ns.adobe.com/photoshop/1.0/";
md.Keywords = md.Keywords + ";" + nameParts.join(',').replace(/,/g,';');
}
};
Copy link to clipboard
Copied
Thanks very much for the answer! Big Help!!
Can you please clarify why "md.namespace" needs to be set and does it need to be the value you suggested in the code ?
Thanks again!!
Copy link to clipboard
Copied
You need a namespace to get one of it's properties.
Here is an example of getting the keywords three different ways.
#target bridge;
if(app.document.selectionsLength>0){
var t = app.document.selections[0];
var md = t.synchronousMetadata;
var Keywords = md.read("http://ns.adobe.com/photoshop/1.0/","Keywords").toString();
alert("Photoshop Namespace = " + Keywords);
/////////////////////////////////////////////////////////
var Keys = md.read("http://purl.org/dc/elements/1.1/","subject").toString();
alert("Dublin Core Namespace = " +Keys);
//////////////////////////////////////////////////////////
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpFile = new XMPFile( app.document.selections[0].spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var xmp = xmpFile.getXMP();
var keys = getArrayItems(XMPConst.NS_DC,'subject');
alert("Dublin Core again = " + keys.toString());
////////////////////////////////////////////////////////////
function getArrayItems(ns, prop){
var arrItem=[];
var items = xmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(xmp.getArrayItem(ns, prop, i));
}
return arrItem;
}
}
Copy link to clipboard
Copied
Great! Thanks very much for your detailed information! Much appreciated