Skip to main content
Known Participant
December 29, 2009
Answered

Getting Metadata information from unedited images (CS3, AS, JS)

  • December 29, 2009
  • 1 reply
  • 2821 views

I have tried in AppleScript and JavaScript to get picture captions using linkXmp.description.

It works when the picture has been edited in Photoshop, but not when it has just been imported  into the page and nothing done to it ... The response is "No Metadata information available", an honest enough answer because it does not deny that the information might be there.

I have got a working AppleScript which goes to Photoshop, opens the image, gets the information, closes without saving and returns to InDesign to place an overlay on the picture with its caption information.The delay time involved in opening the image is irritating, however.

I initially tried this in AppleScript and when baulked read in this forum's archives about the edited vs. unedited problem.

So I headed over to the Photoshop Forum where a helpful chap gave me an AppleScript fragment for getting the caption information and a JavaScript fragment for getting the linkXmp.description in InDesign.

I have just finished adapting the JavaScript to work with a selected item on an InDesign page (learned a lot in the process). But in the end I was faced with the same brick wall I encountered using AppleScript ... if the pic ain't edited, no dice.

My Photoshopping friend seemd surprised I hadn't raised my difficulty in the InDesign Forum... which I am doing so now, with apologies to anyone who may have read me going on about it across the road.

So, is there an InDesign-only method of getting this caption information?

This topic has been closed for replies.
Correct answer Michael_L_Hale

In case anyone else runs into this here is an example that tries to get the caption from Bridge for files that don't have xmp data.

#target indesign
main(); // Call to the main function
function main() {
     if (app.documents.length == 0) {
          alert("Please have an 'Indesign' document before running this script.");
          return;
     }
     docRef = app.activeDocument;
     with(docRef) {
          // try reading linkXmp
          var caption = links[0].linkXmp.description;
          if( caption == "" ) getCaptionFromBridge( links[0].filePath );

     }
     return caption;

     function getCaptionFromBridge( fileName ){
           var cap = undefined;
           function myReturnValue(cap){
                //do what you want with the results
                 cap = cap;
                caption = cap;
           }
           var bt = new BridgeTalk;
           bt.target = "bridge";
           var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+fileName.toSource()+");");
           bt.body = myScript;
           bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
           bt.send();
           bt.pump();
          $.sleep( 100 );
          var timeOutAt = ( new Date() ).getTime() + 500;
          var currentTime = ( new Date() ).getTime();
          while ( ( currentTime < timeOutAt ) && ( undefined == cap ) ) {
               bt.pump();
               $.sleep( 100 );
               currentTime = ( new Date() ).getTime();
           }
           function psRemote(fileName){
           var file = new File(fileName); 
           var tn= new Thumbnail(file);
           var md = tn.synchronousMetadata;
           var caption = md.read('http://purl.org/dc/elements/1.1/',"description/*[1]");
           return caption;
           }
     }
}

1 reply

Legend
December 29, 2009

Probably your "unedited" images do not have XMP metadata. You can verify that if you open the images with a plain text editor. In the edited version you will find that enormous XMP / XML section, the XMP should be missing within the unedited image.

InDesign relies on XMP and does not consider IPTC or EXIF metadata, while the roundtrip thru PS will copy the information into a new XMP section.

There is no direct way to access the IPTC or EXIF by script or even by plugin (as far as I know - I once wrote my own image parsers for a plugin, but that is not scriptable). Eventually you could start Bridge and use methods from there, but I never tried that.

Dirk

Michael_L_HaleCorrect answer
Inspiring
December 31, 2009

In case anyone else runs into this here is an example that tries to get the caption from Bridge for files that don't have xmp data.

#target indesign
main(); // Call to the main function
function main() {
     if (app.documents.length == 0) {
          alert("Please have an 'Indesign' document before running this script.");
          return;
     }
     docRef = app.activeDocument;
     with(docRef) {
          // try reading linkXmp
          var caption = links[0].linkXmp.description;
          if( caption == "" ) getCaptionFromBridge( links[0].filePath );

     }
     return caption;

     function getCaptionFromBridge( fileName ){
           var cap = undefined;
           function myReturnValue(cap){
                //do what you want with the results
                 cap = cap;
                caption = cap;
           }
           var bt = new BridgeTalk;
           bt.target = "bridge";
           var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+fileName.toSource()+");");
           bt.body = myScript;
           bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
           bt.send();
           bt.pump();
          $.sleep( 100 );
          var timeOutAt = ( new Date() ).getTime() + 500;
          var currentTime = ( new Date() ).getTime();
          while ( ( currentTime < timeOutAt ) && ( undefined == cap ) ) {
               bt.pump();
               $.sleep( 100 );
               currentTime = ( new Date() ).getTime();
           }
           function psRemote(fileName){
           var file = new File(fileName); 
           var tn= new Thumbnail(file);
           var md = tn.synchronousMetadata;
           var caption = md.read('http://purl.org/dc/elements/1.1/',"description/*[1]");
           return caption;
           }
     }
}

Legend
December 31, 2009

Thanks for the example.

Please see http://forums.adobe.com/message/2424384 for alternatives to $.sleep() ...

Dirk