Is it possible: Automated meta tagging from filename

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

eilsoe

Is it possible: Automated meta tagging from filename

Post by eilsoe »

Hey all

I need a script that runs through a series images, and automatically tags them using parameters from the filename. I've got a total of 5600 tiff files, all named using "_" seperated parameters, i.e. "VC" for "VolumeControl" and "RIC-S" for "Receiver S".

The flow would be something like:

1) Open file from folder
2) Check file name and seperate parameters into array (seperate by "_")
2) Loop through array and append meta keywords using parameters (i.e. "VC" -> "Volume Control")
3) Save image
4) Next image

Example file name could be "M_Standard_PK_ELAN_InstantDouble_L_BlackGradient.tif".

The master folder contains several subfolders, where each subfolder can contain an abitrary number of additional subfolders (I think 10 or so levels deep, depending on the product itself)

Is this even possible? And if so, where do I begin?

Basically, I only need to know how to open an image, read the filename, append meta keywords and save.

So far I've managed to build a script, at allows me to save a series of Tiff images, using a pre-determined prefix, that appends the name of sub-layersets in a master layerset.

Said script saved me a weeks worth of time, as I had to save all 5600 manually from PS, ticking off various layers/layersets, and looping through a master layerset containing all possible colorvariations for one specific product.

Now I need to meta tag the whole shabang :-/
Paul MR

Is it possible: Automated meta tagging from filename

Post by Paul MR »

Photoshop CS4 or better required!
This should be close, you will need to add to the switch statement though...

Code: Select all#target photoshop
app.bringToFront();

function main(){
var folders =[];
var topLevel = Folder.selectDialog("Please select top level folder");   
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var a in folders){
var fileList = folders[a].getFiles("*.tif");
for(var f in fileList){
var fileName = decodeURI(fileList[f].name).replace(/\.[^\.]+$/, '');
var bits = fileName.split("_");
for(var b in bits){
    switch(bits.toString().toLowerCase()){
        case "vc" : setKeyword(fileList[f], "Volume Control"); break;
        case "ric-s" : setKeyword(fileList[f],"Receiver S"); break;
        default : break;
        }//end switch
    }//end bits
    }//end fileList
    }//end folders
}
main();
function setKeyword(file,key){
       if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
        var xmp = xmpf.getXMP();
        xmp.appendArrayItem(XMPConst.NS_DC, "subject", key, 0,XMPConst.PROP_IS_ARRAY);
        xmpf.putXMP( xmp );
        xmpf.closeFile();
}
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;
}
eilsoe

Is it possible: Automated meta tagging from filename

Post by eilsoe »

HA!

Thanks I didn't expect anyone to actually write to damn thing for me

That just awesome, now I only need to figure out how to target the "description" field as well.

Thanks a freakin' million
Paul MR

Is it possible: Automated meta tagging from filename

Post by Paul MR »

Here is a function for the description...

Code: Select allfunction setDescription(file,desc){
       if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
        var xmp = xmpf.getXMP();
        xmp.deleteProperty(XMPConst.NS_DC, "description");
        xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", desc );
        xmpf.putXMP( xmp );
        xmpf.closeFile();
}