Skip to main content
May 28, 2010
Answered

script to read IPTC description

  • May 28, 2010
  • 1 reply
  • 774 views

Hi,

i need a script so that i can read the description field of the IPTC core of a selected file (and also preferabely the ability for selection of files) in bridge (in my case CS4)

and also please introduce some string manipulation functions to apply to the read field.

Thanks in advance.

This topic has been closed for replies.
Correct answer Paul Riggott

This will write the selected documents description field to the console in the ExtendScript Toolkit.

You will have to be more precise on what you want to do with the string to be able to give an example.


#target bridge
loadXMPLibrary();
for(var a in app.document.selections){
var thumb = app.document.selections;
if(thumb.hasMetadata){
        var selectedFile = thumb.spec;
  var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
  var myXmp = myXmpFile.getXMP();           
   for(var i = 1;i <= items;i++){
var Desc = ArrayItems(XMPConst.NS_DC, "description");
            $.writeln(Desc);
        }      
}
     unloadXMPLibrary();
}

function loadXMPLibrary(){
   if ( !ExternalObject.AdobeXMPScript ){
      try{
         ExternalObject.AdobeXMPScript = new ExternalObject
                                    ( 'lib:AdobeXMPScript' );
      }catch (e){
         alert( ErrStrs.XMPLIB );
         return false;
      }
   }
   return true;
}
function unloadXMPLibrary(){
   if( ExternalObject.AdobeXMPScript ) {
      try{
         ExternalObject.AdobeXMPScript.unload();
         ExternalObject.AdobeXMPScript = undefined;
      }catch (e){
         alert( ErrStrs.XMPLIB );
      }
   }
}

function ArrayItems(ns, prop){
arrItem='';
  var items = myXmp.countArrayItems(ns, prop);
  if(items > 0){ 
   for(var i = 1;i <= items;i++){
     arrItem += myXmp.getArrayItem(XMPConst.NS_DC, prop, i);
   }
  }
    return arrItem;
}

Paul Riggott
Paul RiggottCorrect answer
Inspiring
May 28, 2010

This will write the selected documents description field to the console in the ExtendScript Toolkit.

You will have to be more precise on what you want to do with the string to be able to give an example.


#target bridge
loadXMPLibrary();
for(var a in app.document.selections){
var thumb = app.document.selections;
if(thumb.hasMetadata){
        var selectedFile = thumb.spec;
  var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
  var myXmp = myXmpFile.getXMP();           
   for(var i = 1;i <= items;i++){
var Desc = ArrayItems(XMPConst.NS_DC, "description");
            $.writeln(Desc);
        }      
}
     unloadXMPLibrary();
}

function loadXMPLibrary(){
   if ( !ExternalObject.AdobeXMPScript ){
      try{
         ExternalObject.AdobeXMPScript = new ExternalObject
                                    ( 'lib:AdobeXMPScript' );
      }catch (e){
         alert( ErrStrs.XMPLIB );
         return false;
      }
   }
   return true;
}
function unloadXMPLibrary(){
   if( ExternalObject.AdobeXMPScript ) {
      try{
         ExternalObject.AdobeXMPScript.unload();
         ExternalObject.AdobeXMPScript = undefined;
      }catch (e){
         alert( ErrStrs.XMPLIB );
      }
   }
}

function ArrayItems(ns, prop){
arrItem='';
  var items = myXmp.countArrayItems(ns, prop);
  if(items > 0){ 
   for(var i = 1;i <= items;i++){
     arrItem += myXmp.getArrayItem(XMPConst.NS_DC, prop, i);
   }
  }
    return arrItem;
}