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

Write metadata "instructions"

Advocate ,
Apr 19, 2013 Apr 19, 2013

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.7K

Translate

Translate

Report

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

Valorous Hero , Apr 22, 2013 Apr 22, 2013

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 += "<

...

Votes

Translate

Translate
Guru ,
Apr 20, 2013 Apr 20, 2013

Copy link to clipboard

Copied

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; };

     };

};

Votes

Translate

Translate

Report

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
Advocate ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

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…

Votes

Translate

Translate

Report

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
Valorous Hero ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

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);

    };

};


Votes

Translate

Translate

Report

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
Advocate ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

Hi Paul and Muppet.

Paul...I tried to your refinements and in the first momment it was not working too. BUT...Below the code there´s more lines that involves metadata. I perceived If I remove this additional portion (that specifies to includes more keywords in the images)..then the Instructions is included correct. So the problem is:

1. If the portion below continues in the script, then keywords are assigned to images but instructions no.

2. If I take off this portion, instructions is assigned.

See it:

if (sel.label == "Selecionado" || sel.label == "Selecionado com ajustes"){

                var meta = sel.synchronousMetadata;

                meta.namespace = "http://ns.adobe.com/photoshop/1.0/";            

                if (gravarCD.value){

                    meta.Keywords = metadados.Keywords + "; cd";           

                };   

                if (enviarEmail.value){

                    metadados.keywords = metadados.Keywords + "; email";                

                };   

                if (liberado.value){

                    metadados.keywords = metadados.Keywords + "; liberado";           

                };   

                if (promocao.value){

                    metadados.keywords = metadados.Keywords + "; promoção (" + quantidadeCampo.text + ")";            

                };

            };

Votes

Translate

Translate

Report

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
Valorous Hero ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

Something like 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 (sel.label == "Selecionado" || sel.label == "Selecionado com ajustes"){          
                if (gravarCD.value){
                 xmp.appendArrayItem(XMPConst.NS_DC, "subject", "cd", 0,XMPConst.PROP_IS_ARRAY);      
                };   
                if (enviarEmail.value){
                    xmp.appendArrayItem(XMPConst.NS_DC, "subject", "email", 0,XMPConst.PROP_IS_ARRAY);                 
                };   
                if (liberado.value){
                    xmp.appendArrayItem(XMPConst.NS_DC, "subject", "liberado", 0,XMPConst.PROP_IS_ARRAY);         
                };   
                if (promocao.value){
                    xmp.appendArrayItem(XMPConst.NS_DC, "subject", "promoção (" + quantidadeCampo.text + ")", 0,XMPConst.PROP_IS_ARRAY);           
                };
};
if (xFile.canPutXMP(xmp)){
     xFile.putXMP(xmp);
     xFile.closeFile(XMPConst.CLOSE_UPDATE_SAFETY);
    };
};

Votes

Translate

Translate

Report

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
Advocate ,
Apr 23, 2013 Apr 23, 2013

Copy link to clipboard

Copied

Perfect, Paul.

Now it worked.

Just for curiosity. Why you set "subject" instead of "keywords" in the parameters??

Best Regards

Gustavo.

Votes

Translate

Translate

Report

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
Valorous Hero ,
Apr 23, 2013 Apr 23, 2013

Copy link to clipboard

Copied

This is the field name for Keywords in the Dublin Core Namespace.

You can see this if you go to file info and look at the advanced tab or the raw data tab.

DC-Subject.jpg

Hope this helps.

Votes

Translate

Translate

Report

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
Advocate ,
Apr 23, 2013 Apr 23, 2013

Copy link to clipboard

Copied

LATEST

Perfect. Thank you a lot Paul

Helps a lot.

All my best

Gustavo.

Votes

Translate

Translate

Report

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