Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Dec 29, 2009 Dec 29, 2009

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?

TOPICS
Scripting
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Dec 30, 2009 Dec 30, 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

...
Translate
Mentor ,
Dec 29, 2009 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 30, 2009 Dec 30, 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;
           }
     }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 30, 2009 Dec 30, 2009

Thanks for the example.

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

Dirk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 31, 2009 Dec 31, 2009

Thanks for the link. I had read that thread before but forgot about it.

The code I posted is the result of several of us trying to help the op in the Photoshop scripting forum. http://forums.adobe.com/thread/543880

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 04, 2010 Jan 04, 2010

PS ... I have run into a small problem when running my caption grabbing script from within the InDesign script panel.

When the script is run on an image without an XMP description, it makes use of the BridgeTalk function. If it is the first time the script has encountered a particular image, it reports that there is no caption (even though I know perfectly well there is one).

So I run the script again and on the second time of asking I get the caption.

On one occasion the caption's arrival was followed in quick order by the firing up of the ExtendScript Toolkit, which tried and failed to load the InDesign help.

This "run two times to get a result" business did not, as far as I can recall, arise while I was debugging in ExtendScript.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 04, 2010 Jan 04, 2010

I wonder if the problem is not that it's the first time Bridge has encountered the image and the script times out before Bridge is finished caching the file. I didn't have any images that had the caption only in EXIF so I had to create one using Exiftools. So I only tested using that one file.

To make it easier to adjust the timeout for the message, you might want to change the message using the info from the link in Dirk's post.

     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(10);// send message synchronously and wait up to 10 seconds for responce
           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;
           }
     }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 04, 2010 Jan 04, 2010

You may also want to look at thumbnail synchronousMetadata according to my docs which are pretty dated now (CS2) it attempts to retrieve this info for only 3 seconds. (or at least thats what I thought it meant?) Just something else to add to the mix.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 04, 2010 Jan 04, 2010

Tried the simplified BridgeTalk function. All sweet after I doubled the timeout! Fingers crossed, that's this one laid to rest. Thanks again for all your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 04, 2010 Jan 04, 2010

20 seconds is a long time to wait. The CS3 and CS4 ESKT object viewer for Bridge doesn't say anything about a timeout for synchronousMetadata. It says it waits for valid values or returns undefined for formats that don't support metadata. Could be Adobe changed that or that detail got lost during some edit of the DOM docs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2010 Jan 05, 2010

You are probably right. I'll look at that timeout again when I've got the script back in the more hostile environment of the office. Things do happen a lot more slowly in a network that includes an undersea section.

I discovered why the ExtendScript Toolkit kept sticking its nose in.

I'm afraid it's confession time: The surgeon left an instrument in the patient/victim... to wit, a "$.write()" hiding out between a couple of the functions!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 05, 2010 Jan 05, 2010
LATEST

Mike, it may well have changed then I was only going quoting from my docs (which I said are out of touch and to check)

Thumbnail object properties:

synchronousMetadata:

Metadata:

Waits up to three seconds to return the Metadata Object associated with this thumbnail, if it can be found. Read only.

I read that as having a timeout of its own is that right?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines