Copy link to clipboard
Copied
Hi all, I was trying to find some solution online and customize amazing script from Paul Riggott, but I am not able to make it work the way I need.
I have my client images organized in folders and subfolders structure. For all images (thousands of files in many subfolders) I need an Adobe Bridge script to take the whole path of image file, separate from path individual names of folders and store these folders as separate keywords in image metadata.
For example, I have image A.jpg in folder /Work/Job01/PartA/Photos and image B.jpg in folder /Work/Job02/PartB/Photos. After I run the script from Adobe Bridge on folder /Work, I would like to have for both images added keywords
A.jpg: Work; Job01; PartA; Photos
B.jpg: Work; Job02; PartB; Photos
As “Work” and “Photos” folders are usually present, it would be nice to have an opportunity put these two exact strings into script and exclude them from keywords added, but it is not necessary 🙂
The script bellow adds just one keyword ~/Work/Job01/PartA/Photos, so what is needed is to split it and make separate keywords from substrings. This would allow me to move images anywhere and still be able to filter them as group in structure (like Job number, or Part name).
Please, could anyone show me how to update that script? Or is there any other solution I just have not found yet?
Thanks, Petr
// ADOBE BRIDGE SCRIPT // PUT FOLDER NAMES TO IPTC KEYWORDS
// from Paul Riggott Script, May 12, 2011 12:23 PM (in response to JSG_Alex_B)
// https://forums.adobe.com/thread/656144
#target bridge
if( BridgeTalk.appName == "bridge" ) {
AddFolderNameToMeta = MenuElement.create("command", "Add folder names as keywords", "at the end of Tools");
}
AddFolderNameToMeta.onSelect = function () {
addFolderName();
}
function addFolderName(){
var folders =[];
var Pics=0;
folders = FindAllFolders(Folder(app.document.presentationPath), folders);
folders.unshift(Folder(app.document.presentationPath));
for(var a in folders){
var PictureFiles = folders.getFiles(/\.(jpg|jpe|jpeg|gif|eps|dng|bmp|tif|tiff|psd|rle|dib|cin|dpx|sct|pbm|flm|psb|exr|pcx|pdp|...
for(var p in PictureFiles){
addKeyword(PictureFiles
)
Pics++;
}
}
alert("Number of Folders Processed = "+folders.length+ " Documents Processed = "+Pics);
function addKeyword(fileName){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var thumb = new Thumbnail(fileName);
// I need somehow to make substrings from path to separate individual folder subfolder names and add these as separate keywords
var folderName = decodeURI(fileName.path).replace(new RegExp(/\\/g),';');
if(thumb.hasMetadata){
var selectedFile = thumb.spec;
try{
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
var keys = getArrayItems(XMPConst.NS_DC,'subject');
keys.unshift(folderName);
keys= ReturnUniqueSortedList(keys);
myXmp.deleteProperty(XMPConst.NS_DC,'subject');
for(var z in keys){
myXmp.appendArrayItem(XMPConst.NS_DC, "subject", keys
, 0,XMPConst.PROP_IS_ARRAY); }
}catch(e){}
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
function getArrayItems(ns, prop){
var arrItem=[];
var items = myXmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(myXmp.getArrayItem(ns, prop, i));
}
return arrItem;
}
};
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray;
if ( fileFoldObj instanceof File ) {
} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
}
}
return destArray;
}
function ReturnUniqueSortedList(ArrayName){
var unduped = new Object;
for (var i = 0; i < ArrayName.length; i++) {
unduped[ArrayName] = ArrayName;
}
var uniques = new Array;for (var k in unduped) {
uniques.push(unduped
); }
uniques.sort();
return uniques;
}
};
The only other option that I know of is using ExifTool:
Copy link to clipboard
Copied
The only other option that I know of is using ExifTool:
Copy link to clipboard
Copied
Well, I tried not to use a command line tool, but it seems it will be quicker, so thanks, Stephen, for encouraging me 🙂
Copy link to clipboard
Copied
Yes, ExifTool is quicker than waiting for help or learning to script from scratch. Don’t give up hope though, perhaps somebody will know how to extend the script. As powerful as ExifTool is, I prefer a Bridge solution where possible, even if it is scripted. At least on a Mac, it is possible to enter the ExifTool CLI code into an Automator Service, so that various ExifTool commands can be run via a contextual right click on a file or folder – which makes the process more accessible.