Skip to main content
May 6, 2010
Answered

copy filename to iptc description

  • May 6, 2010
  • 13 replies
  • 14912 views

Hello,

I need to create a process of copying the filename of a tiff to the description in that same file's iptc. Ideally i'd like to be able to drop the script in to an Apple Automator process, but that would be a luxury. There's also an extra catch: i need the script to replace "=" with ":" and to add a prefix, for example "CMS:"

Here's an example:

input

filename: 8737=6.tif

description:

output

filename: 8737=6.tif

description: CMS:8737:6

It seems a faily basic process but i don't know where to start with this scripting business... Any help or advise would be much appreciated! Perhaps you know of a really similar one that i can modify??

Lewis

This topic has been closed for replies.
Correct answer Paul Riggott

Yet another version..


#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 = 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){ }
   }
}

carlgaardner
Participating Frequently
July 2, 2015

Yes, but I would love to use it on TIF's and other file-formats.

So what I need is a script for Bridge that takes the file name without the ".TIF" or ".JPG" or whatever and puts it in IPTC Title or Description-field.

carlgaardner
Participating Frequently
July 1, 2015

Is there a way to get this working with CC?

I may not be smart enough but at least I can't get it working in CC.

I have the exact same need as the original top poster.

Chuck Uebele
Community Expert
Community Expert
July 1, 2015

So far, I was only able to make changes to the XMP sidecar file. I didn't get it to work with dng's, but all I needed was to be able to get get one or the other to work.

With CC.

Paul Riggott
Inspiring
May 6, 2010

This should do selected documents...


#target bridge  
   if( BridgeTalk.appName == "bridge" ) { 
addFileName = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
}
addFileName.onSelect = function () {
   addFileNameToDescription();
   }
function addFileNameToDescription(){
var Prefix = "CMS:";
var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels.synchronousMetadata;
    md.namespace = "http://purl.org/dc/elements/1.1/";
    var Name = decodeURI(sels.name).replace(/\.[^\.]+$/, '');
    Name = Prefix + Name.replace(/\=/g,':');
    md.description = Name;
  }
}

Paul Riggott
Paul RiggottCorrect answer
Inspiring
May 6, 2010

Yet another version..


#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 = 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){ }
   }
}