Skip to main content
May 6, 2010 1:43 PM UTC
Answered

copy filename to iptc description

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 is closed to new replies. Start a new post to keep the conversation going.
Paul Riggott
Paul RiggottCorrect answer
Inspiring
May 6, 2010 3:37 PM UTC

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

70 replies

compupix
Known Participant
May 11, 2019 4:12 AM UTC

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!

Translate
compupix
Known Participant
May 11, 2019 1:43 PM UTC

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!

Translate
carlgaardner
Participating Frequently
Jul 9, 2015 12:55 PM UTC

Thanks, worked like a charm!

Translate
carlgaardner
Participating Frequently
Jul 9, 2015 9:41 AM UTC

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

Translate
Chuck Uebele
Community Expert
Community Expert
Jul 9, 2015 12:31 PM UTC

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 )};

Translate
carlgaardner
Participating Frequently
Jul 6, 2015 6:00 AM UTC

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

BIG THANK YOU guys!

Translate
Jul 2, 2015 3:06 PM UTC

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..

Translate
Chuck Uebele
Community Expert
Community Expert
Jul 2, 2015 5:25 PM UTC

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

Translate
carlgaardner
Participating Frequently
Jul 2, 2015 2:00 PM UTC

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?

Translate
Chuck Uebele
Community Expert
Community Expert
Jul 2, 2015 2:15 PM UTC

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.

Translate
carlgaardner
Participating Frequently
Jul 2, 2015 11:03 AM UTC

OK anyone here that gets it to work with CC?

Translate
Chuck Uebele
Community Expert
Community Expert
Jul 2, 2015 1:48 PM UTC

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 );

    

      }

    

Translate
Inspiring
Jul 2, 2015 1:56 PM UTC

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

Translate
Jul 2, 2015 10:27 AM UTC

No I'm using Bridge CS5.

Translate
carlgaardner
Participating Frequently
Jul 2, 2015 9:53 AM UTC

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?

Translate
Jul 2, 2015 9:08 AM UTC

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

Translate
Chuck Uebele
Community Expert
Community Expert
Jul 2, 2015 2:40 PM UTC

I would download the XMP SDK. it is a real pain trying to figure out what works!!!

Adobe - XMP Developer Center | Adobe Developer Connection

Translate