Skip to main content
May 6, 2010
Answered

copy filename to iptc description

  • May 6, 2010
  • 13 replies
  • 14911 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){ }
   }
}

compupix
Known Participant
May 11, 2019

I would like to stuff the following information into the description:

{old description} + “ “ + {file name sans extension} + “ “ + {date created}

Using the indicated “Correct Answer by Paul Riggott on May 6, 2010 8:37 AM”

I’ve been able to stuff the file name sans extension into the description. I haven’t been able to add the old description and original creation date.

Thanks!

compupix
Known Participant
May 11, 2019

Thanks SuperMerlin.

That preserves the old description and adds the full file name and the creation time. Is it possible to add the file name without the extension and the creation date only.

Current output:

... 1823-017.jpg 2019-04-07T08:47:28.00

Desired output:

... 1823-017 2019-04-07

Even better would be to format the date as mm-dd-yyyy.

Thanks!

carlgaardner
Participating Frequently
July 9, 2015

Thanks, worked like a charm!

carlgaardner
Participating Frequently
July 9, 2015

I just noticed that the script adds a "space" (" ") before the filename, is this an easy thing to fix?

Chuck Uebele
Community Expert
Community Expert
July 9, 2015

Rather than this line:

xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",desc + " " +Name );

Replace it with these lines:

if(!desc || desc ==''){xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",Name )}

else{xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",desc + " " +Name )};

carlgaardner
Participating Frequently
July 6, 2015

Yep that worked, all I have to do is run the script twice, second time overwrites the undefined-part.

BIG THANK YOU guys!

July 2, 2015

Yes indeed, I can't find what I'm looking for. Some examples with IPTC Extension would be very helpfull. I don't have enough background knowledge to figure it out myself..

Chuck Uebele
Community Expert
Community Expert
July 2, 2015

I wish I could help more, but I fish around for the correct way to do this also.

carlgaardner
Participating Frequently
July 2, 2015

OK, so I run the script above from Adobe Extendscript Toolkit CC (as Extendscript or Bridge?).

Then I run Bridge, and where in Bridge do I find a way to run this script on the files I've selected?

Chuck Uebele
Community Expert
Community Expert
July 2, 2015

You just select the thumbnails that you want to run the script on. You can set it up to run from Bridge rather than ESTK, but I didn't include that in the script. I don't do a lot of Bridge scripting, but I did recently need to do this with some images I was digitizing: copying descriptions from my FileMaker database into the description fields of my images.

carlgaardner
Participating Frequently
July 2, 2015

OK anyone here that gets it to work with CC?

Chuck Uebele
Community Expert
Community Expert
July 2, 2015

Here's a script that will put the file name in the description field. Select a thumbnail in Bridge. Run the script from ESTK.

#target bridge

var tSpec, fName, xmpFile, nName;

if (ExternalObject.AdobeXMPScript == undefined) {

    ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

}

var doc = app.document

var thumbs = doc.selections

for(var i=0;i<thumbs.length;i++){

  

    tSpec = thumbs.spec;

    fName = tSpec.fsName.split('.')[0];

    var testFile = new File(tSpec)

    readTextFile (testFile)

    };//end for thumbs loop

function readTextFile(file){

      var xmpf = new XMPFile(File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );

      var xmp = xmpf.getXMP();

                  

                  xmp.deleteProperty(XMPConst.NS_DC, "description");

                  xmp.setProperty( XMPConst.NS_DC, "description", file.name, XMPConst.STRING );

                  if (xmpf.canPutXMP( xmp )) {

                  xmpf.putXMP( xmp );

                  }

            xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );

    

      }

    

Inspiring
July 2, 2015

You are not passing fName to the readTextFile function and only updating the description with the full name including extension.

July 2, 2015

No I'm using Bridge CS5.

carlgaardner
Participating Frequently
July 2, 2015

OK, so this script works for You rd2487, and youre using Bridge CC?

If so then I must be doing something wrong, could you please explain in detail how you get it into Bridge and how You then use it in Bridge.

All the scripts I've tried with show up in the options/startup scripts dialog, but I get no menu item or nothing when I right mouse click, I don't understand how to use it?

July 2, 2015

Hi everyone,

this script works very well for me, but I need to write the filename to an IPTC extension field: Source Inventory Number {Artwork or Object detail}

After a long search I finally found this document (https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata-201410_3.pdf) in wich there is a specification for this field (page 51).

But I can't manage to implement it properly in the code, could someone help me please?

Kind regards,

rd

DomiPro
Known Participant
November 19, 2015

Hi, I need to do this also.

I see here that it's possible to to copy to the Description field, but can someone please adapt this script  ?

My client is asking to put the Filename of thousand images into the field ‘Source Inventory Number’ in the IPTC Extension - Artwork or Object.

I need to do this in Bridge CC.

Also the filename has underscores who has to be changed in slashes when copied: S2004_16_001 should become S2004/16/001 in the field 'Source Inventory Number'; they remain unchanged in the Filename.

Thanks, Dominique

DomiPro
Known Participant
November 20, 2015

I'm still trying to figure out how to add various information to the various metadata fields. It can be done, but you have to know the right namespace and structure of each of the fields. I would suggest you ask your question in the XMP SDK forum:

XMP SDK


Could this document (https://iptc.org/std/photometadata/specification/IPTC-PhotoMetadata-201410_3.pdf) help in wich there is a specification for this field (page 51).