Skip to main content
Participant
July 27, 2010
Question

Replace "Description" metadata with string script.

  • July 27, 2010
  • 1 reply
  • 1352 views

I'm working with a script to assign a string (in this case, the color of the product in the image) to the description field in the image's metadata. It would save time on the layout side by taking advantage of InDesign's live caption capabilities. I'm processing the selections with a for loop, and the script will either work, or return an error: "XMP Exception: LFA_Close: FSCloseFork failure" I can't reliably duplicate the error, sometimes I can process all the images, and other times it errors out after the first one. Does anyone have a description of the error, and/or any suggestions on how to fix it?

Using Bridge CS5

-S

function writecolortodescription(colorway,myimage){
// adds the colorway name to the "Description" field in the metadata to take advantage of InDesign CS5's live caption features.
// borrowed heavily from a script by Paul Riggott (adobe forums)
loadXMPLib();
    var thumb = new Thumbnail(myimage);
    if(thumb.hasMetadata){
      var selectedFile = thumb.spec;   
      var myXmpFile = new XMPFile(selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);      
      var myXmp = myXmpFile.getXMP();   
     
      myXmp.deleteProperty(XMPConst.NS_DC, "description");
      myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",colorway);
      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){ }
   }
}

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
July 28, 2010

Pure guess work, but it looks as if there could be a problem with opening some of your files and the close is generating an error. There isn't any error checking so you could put some alerts in or even write the errors to a file.

This has now got error checking on the save and will just do a close on error, so this might work but you will still have the problem of not know what files have not been updated.


function writecolortodescription(colorway,myimage){
// adds the colorway name to the "Description" field in the metadata to take advantage of InDesign CS5's live caption features.
// borrowed heavily from a script by Paul Riggott (adobe forums)
loadXMPLib();
    var thumb = new Thumbnail(myimage);
    if(thumb.hasMetadata){
      var selectedFile = thumb.spec;   
      var myXmpFile = new XMPFile(selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);      
      var myXmp = myXmpFile.getXMP();   
     
      myXmp.deleteProperty(XMPConst.NS_DC, "description");
      myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default",colorway);
      if (myXmpFile.canPutXMP(myXmp)) {
    myXmpFile.putXMP(myXmp);
    try{
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }catch(e){

          //You could write out the details to an external file here.
             myXmpFile.closeFile();
             }
         }
      }
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){ }
   }
}