Skip to main content
July 19, 2010
Question

Copy filename to iptc description with changes

  • July 19, 2010
  • 1 reply
  • 672 views

Hello,

I'm looking for a script for copying the filename of a tiff to the description in that same file's iptc, with a couple of contextual changes to the name.

Those changes are:

replace any = with :

replace any * with /

add the prefix "CMS:"

So here's an example:

input

filename: 87*37=6.tif

description:

output

filename: 87*37=6.tif

description: CMS:87/37:6

I had a script that did some of these things for a while, but it was quite slow and I don't know how to rewrite it.

Thank you in advance for any help,

Lewis

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
July 19, 2010

This is the same script as before with an extra line to change the asterisk..


#target bridge  
   if( BridgeTalk.appName == "bridge" ) { 
FileNameToDesc = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
}
FileNameToDesc.onSelect = function () {
   updateFileName();
   }
     
function updateFileName(){
loadXMPLib();
var Prefix = "CMS:";
var sels = app.document.selections;
for(var a in sels){
var thumb = new Thumbnail(sels);
   if(thumb.hasMetadata){
      var selectedFile = thumb.spec;   
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);      
      var myXmp = myXmpFile.getXMP();   
      var Name = decodeURI(sels
.name).replace(/\.[^\.]+$/, '');
      Name = Name.replace(/\*/g,'/');
        Name = Prefix + Name.replace(/\=/g,':');
      myXmp.deleteProperty(XMPConst.NS_DC, "description");
      myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",Name );
      if (myXmpFile.canPutXMP(myXmp)) {
    myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
      }
}
unloadXMPLib();
}
function loadXMPLib(){
if (ExternalObject.AdobeXMPScript == undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
}
}
function unloadXMPLib(){
   if( ExternalObject.AdobeXMPScript ) {
      try{
         ExternalObject.AdobeXMPScript.unload();
         ExternalObject.AdobeXMPScript = undefined;
      }catch (e){ }
   }
}