Skip to main content
Inspiring
Apr 19, 2013 12:54 PM UTC
Answered

Write metadata "instructions"

Hi

I´m trying to edit the metadata "instructions" in some photos vieweb by Bridge. At true, I need to preserve what´s already written in this field, then add some more things via script.

Here´s my try:

var doc = app.document;

doc.selectAll();

var sel = doc.getSelection ("psd, ai, tif, tiff, jpg, png, bmp, jpeg");

if (ExternalObject.AdobeXMPScript==undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

for (var g=0 ; g<sel.length ; g++){

     var xFile = new XMPFile (sel.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

     var xmp = xFile.getXMP();

     var x = sel.metadata;

     var instruc = new String (x.read ("http://ns.adobe.com/photoshop/1.0/", "Instructions"));

     instruc = instruc + "<test bonus instruction>";

     //up to this line, everything is right

     xmp.deleteProperty (XMPConst.NS_XML, "instructions") //problem is this line and/or the line below. It does not return error, but do not write too.

     xmp.appendArrayItem(XMPConst.NS_XML, "instructions", instruc, 0, XMPConst.ARRAY_IS_ORDERED); //problem can be here.

};

if (xFile.canPutXMP(xmp)){

     xFile.putXMP(xmp);

     xFile.closeFile(XMPConst.CLOSE_UPDATE_SAFETY);

};

What Am I missing?

Thank you a lot for the help

Best Regards

Gustavo.

This topic is closed to new replies. Start a new post to keep the conversation going.
Paul Riggott
Paul RiggottCorrect answer
Inspiring
Apr 22, 2013 3:00 PM UTC

You could try this...

var doc = app.document;

doc.selectAll();

var sel = doc.getSelection ("psd, ai, tif, tiff, jpg, png, bmp, jpeg");

if (ExternalObject.AdobeXMPScript==undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

for (var g=0 ; g<sel.length ; g++){

     var xFile = new XMPFile (sel.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

     var xmp = xFile.getXMP();

     var instruc = xmp.getProperty (XMPConst.NS_PHOTOSHOP, "Instructions");

     instruc += "<test bonus instruction>";

     xmp.deleteProperty (XMPConst.NS_PHOTOSHOP, "Instructions");

     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Instructions", instruc);

if (xFile.canPutXMP(xmp)){

     xFile.putXMP(xmp);

     xFile.closeFile(XMPConst.CLOSE_UPDATE_SAFETY);

    };

};


9 replies

Inspiring
Apr 20, 2013 5:32 PM UTC

Gustavo… XMP is not one of my great strengths so I may well be wrong… Anyhows I don't this the instructions property is an Array but a simple String…

#target bridge

if ( loadXMPLibrary() ) { processThumbnails() };

if ( unloadXMPLibrary() ) { alert( 'were done' ) };

/*

     Process the thumbnails in Bridge

*/

function processThumbnails() {

 

     var i, count, doc, smd, inst;

 

     doc = app.document;

 

     count  = doc.visibleThumbnailsLength;

 

     for ( i = 0; i < count; i++ ) {

 

          if ( /\.(ai|bmp|jpg|jpeg|png|psd|tif+)$/.test( doc.visibleThumbnails.name ) ) {

 

               if ( doc.visibleThumbnails.hasMetadata ) {

 

                    smd = doc.visibleThumbnails.synchronousMetadata;

 

                    inst = smd.read( 'http://ns.adobe.com/photoshop/1.0/', 'Instructions' );

 

                    undateXMP( doc.visibleThumbnails, inst );

 

               };

 

          };

 

     };

 

};

/*

     Update the XMP properties…

*/

function undateXMP( thumb, inst ) {

 

     var xmpFile, xmp;

 

     xmpFile = new XMPFile( thumb.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );

                    

     xmp = xmpFile.getXMP();

                    

     inst += ', elmo';

 

     // The line below returns an XMP error the property is NOT an Array…

 

     //xmp.appendArrayItem( 'http://ns.adobe.com/photoshop/1.0/', 'Instructions', XMPConst.PROP_IS_ARRAY, inst, XMPConst.ARRAY_IS_ORDERED );

 

     xmp.setProperty( 'http://ns.adobe.com/photoshop/1.0/', 'Instructions', inst, 0, XMPConst.STRING );

 

     if ( xmpFile.canPutXMP( xmp ) ) {

 

          xmpFile.putXMP( xmp );

                    

          xmpFile.closeFile( XMPConst.CLOSE_UPDATE_SAFETY  );

                    

     };

 

};

/*

     Load the XMP External Object Library

*/

function loadXMPLibrary() {

     if ( !ExternalObject.AdobeXMPScript ) {

 

          try {

 

               ExternalObject.AdobeXMPScript = new ExternalObject( 'lib:AdobeXMPScript' );

 

               return true;

          } catch(e) { return false; };

 

     };

};

/*

     Unload the XMP External Object Library

*/

function unloadXMPLibrary() {

     if ( ExternalObject.AdobeXMPScript ) {

          try {

               ExternalObject.AdobeXMPScript.unload();

 

               ExternalObject.AdobeXMPScript = undefined;

 

               return true;

          } catch(e) { return false; };

     };

};

Translate
Inspiring
Apr 22, 2013 12:00 PM UTC

Hi Muppet

Thank you a lot for your help. If this not subject is not your strenght, for me, metadata is very confused and difficult hehehe.

I tried to change the line you pointed (array to string). The script runned without erros, but instructions were not written in the files. It´s not working yet.

The other field (creator) writes normally.

Any other suggestion?

Thank you so much

Best Regards

Gustavo

Translate
Inspiring
Apr 22, 2013 1:06 PM UTC

Did you try my snippet as is…? XMP like a lot of other things I am still learning myself… The never ending saga goes on…

Translate