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

Set a label based on a metadata field

Advocate ,
Dec 17, 2012 Dec 17, 2012

Hi friends

Would like to know if this can be automatized via a JavaScript.

When I´m in a folder with lots of photos I use green label to choose the photos I want to print.

BUT if I feel I need to correct anything in a selected photo, then I use the blue label for this instead.

So I know if a photo has the green label then I can print directlly. But If a photo has the blue label then I know I need to make adjustments in Photoshop.

---

Now the question:

For blue label photos I use to write instructions directelly to the metadata field called "Instructions" (it´s in the IPTC Core section of metadata). And I´d like a script to automate it. Example:

If I write anything to the "Instructions" field...then automatically apply (or change to) the blue label!

Now If..after...I delete the message on that field...then check if the photo has keywords

         If having....apply the green label.

          If not having...apply NO LABEL.

---

IS it possible to automate it via script?

If yes..then I´ll try to write it

Thank you for the tips.

Gustavo.

TOPICS
Scripting
5.5K
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

Valorous Hero , Dec 18, 2012 Dec 18, 2012

This may help...

#target bridge

app.synchronousMode = true;

var documento = app.document.selections[0];

var xmp = documento.synchronousMetadata;

var instrucao =  "'" + xmp.read ('http://ns.adobe.com/photoshop/1.0/', 'Instructions') + "'";

var Keys = xmp.read('http://purl.org/dc/elements/1.1/','dc:subject');

var BlueLabel = 'Review';

var GreenLabel = 'Approved'

if (instrucao == "''" && Keys.length > 0) {

    documento.label = GreenLabel;

}

if (instrucao == "''" && Keys.length == 0) {

    documento.label = ''

...
Translate
Mentor ,
Dec 17, 2012 Dec 17, 2012

Scripting a label change based on metadata or writing matadata based on labels is scriptable… I don't see anything in bridge's events for thumbnails being modified… although if you modify the metadata the file time stamp gets bumped… so you may be able to watch for that

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
Advocate ,
Dec 17, 2012 Dec 17, 2012

Thank you a lot Muppet.

Will try to write the script. I´ve downloaded the Bridge SDK that contains the Bridge script reference manual. Let´s see how it works

Thank you a lot

Best Regards

Gustavo.

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 17, 2012 Dec 17, 2012

It should also be possible to with document selectionsChanged but Im not sure if that would be annoying… kicking in all the time you would have to try it yourself…

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
Advocate ,
Dec 17, 2012 Dec 17, 2012

Muppet

I´m reading the Bridge Script Manual (since it´s the first time I write a script for this application) and I´m getting confused.

Labels and Keywords and even Metadata are assigned to the "Document" or the "Thumbnail" object?

When declaring to apply or change a label...shoul I invoke the Active document or the Thumbnail of the document?

Thank tou for the tip

Gustavo.

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 17, 2012 Dec 17, 2012

Yes bridge can be a little odd compaired to other apps… Your systems files and folders are thumbnails… the documents are the open UI windows… as these are generally point to folders they too have a thumbnail… hope that makes sence…

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
Advocate ,
Dec 17, 2012 Dec 17, 2012

Hi Muppet...

Yes..Writting scripts to Photoshop and Illustrator looks really easier.

Did not understand "the documents are the open UI windows"

Could you please explain it me better?

Thank you for all the help

Gustavo.

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 17, 2012 Dec 17, 2012

Bridge is a browser… It can look at either your file system or web content… on the mac you will always get a new document when you launch bridge… it should default to where ever it was last looking… The window is your document it contains a mixture of files and folders these are all considered thumbnails… its this array that you want to look at and change the properties of…

Here is one document ( the user interface window ) with an array of 9 thumbnails ( all files no folders )…

Screen shot 2012-12-17 at 19.00.24.png

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
Advocate ,
Dec 17, 2012 Dec 17, 2012

Perfect.

Thank you a lot Muppet.

Will try to write the script then publish where when finishing (or if getting problems).

Best Regards

Gustavo.

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
Advocate ,
Dec 18, 2012 Dec 18, 2012

Hi Muppet

My first test of thi script:

----------

app.synchronousMode = true

var doc = app.document.selections[0];

doc.label = "Adjustments"

doc.hasMetadata

-----

It worked. For the selected image...it applies the label "Adjustments"

Now...I´m trying to acess the "Instructions" field in the IPTC metadata but I´m not getting a way to do it.

Do you have any tip to be able to read it? If having any value..then apply that label.

thank you a lot

Gustavo.

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 18, 2012 Dec 18, 2012

Gustavo… Im at work just now but have very quickly thrown this together for you it may point you in the right direction… You need to read the properties from the thumnails matadata… here is a quick selection loop…

#target bridge

//

labelFiles();

//

function labelFiles() {

   

    var i, count, doc, smd, inst;

   

    doc = app.document;

   

    count = doc.selectionsLength;

   

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

       

        smd = doc.selections.synchronousMetadata;

       

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

       

        if ( inst != '' ) {

           

            alert( inst );

           

            doc.selections.label = 'Adjustments';

         

        };

       

     };

   

};

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
Advocate ,
Dec 18, 2012 Dec 18, 2012

Hi Muppet

Almost. Your code was able to acess the Instructions metadata field but it does not worry if it has or no data...the script is putting that label.

I tried to simplify to script in order to understand myself...But I´m getting the same problem...I do not know what to write in the IF condition to verify if the instructions field has or no data.

See it:

#target bridge

app.synchronousMode = true

var documento = app.document.selections[0];

var xmp = documento.synchronousMetadata

var instrucao

instucao = xmp.read ('http://ns.adobe.com/photoshop/1.0/', 'Instructions')

if (instrucao != ???????) {

    documento.label = "Adjustments"

}

Thank you a lot

Gustavo

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
Valorous Hero ,
Dec 18, 2012 Dec 18, 2012

This may help...

#target bridge

app.synchronousMode = true;

var documento = app.document.selections[0];

var xmp = documento.synchronousMetadata;

var instrucao =  "'" + xmp.read ('http://ns.adobe.com/photoshop/1.0/', 'Instructions') + "'";

var Keys = xmp.read('http://purl.org/dc/elements/1.1/','dc:subject');

var BlueLabel = 'Review';

var GreenLabel = 'Approved'

if (instrucao == "''" && Keys.length > 0) {

    documento.label = GreenLabel;

}

if (instrucao == "''" && Keys.length == 0) {

    documento.label = '';

    }

if (instrucao != "''") {

   documento.label = BlueLabel;

}

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 18, 2012 Dec 18, 2012

Hello, Paul would please explain this what/why you have done here…? I have had several issues when using $.writeln( data ) during debugging in ESTK and Im unsure if this is a solution…? When I alert( someString ) it appears to be what I wanted but if I use $.writeln( someData ) then I get a bunch of junk what am I overlooking here…? is it down to differences in meta characters or something else…?

<![CDATA[]]> what is this all about and how do I deal with stuff like this in ESTK…? as always TVM

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
Valorous Hero ,
Dec 18, 2012 Dec 18, 2012

I used to get that problem as well Mark and the trick is to use quotes IE:

var instrucao =  "'" + xmp.read ('http://ns.adobe.com/photoshop/1.0/', 'Instructions') + "'";

This seems to get around the problem, and you can then remove the quotes with a regex expression.

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 18, 2012 Dec 18, 2012

Paul, I was just studying the syntax and spotted the you concat the read into a single quoted string… Hum I didn't get the same when using inst.toString() even tried inst.toSource() but that said it was a new string… I've had this a cople of times thanks thas on for the notebook ( yeah like I have one )

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
Advocate ,
Dec 19, 2012 Dec 19, 2012

Hi Paul and Muppet

Thank you a lot for the big help and tips.

Paul, I adjusted your suggestion to just what I need and had this result. See:

#target bridge

app.synchronousMode = true;

if (app.document.selectionLength>0) {

    var documento = app.document.selections[0];

    var xmp = documento.synchronousMetadata;

    var instrucao = "" + xmp.read ("http://ns.adobe.com/photoshop/1.0/", "Instructions");

     if (instrucao != "") {

     documento.label = "Adjustments";

   }

}

---

Now a problem. In the Extended Script Toolkit..running as a test..it worked perfectlly.

I tried to insert it in the Bridge Startup Scripting Folder...

After relauching bridge it says it cannot run this script because:

"if (app.document.selectionLength>0) {" is not an object!!!

What Am I missing?

I´d like it to run while I´m in Bridge...so every time I write Instructions to a photo..it automatically set its label to blue (Adjustments).

Thank you a lot again

Best Regards

Gustavo.

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
Valorous Hero ,
Dec 19, 2012 Dec 19, 2012

When bridge is opened it is trying to run the script and at that time nothing is selected, what you need to do is something like this...

#target bridge

if( BridgeTalk.appName == "bridge" ) {

checkInstructions = new MenuElement("command", "Check Instructions", "at the end of Thumbnail");

}

checkInstructions.onSelect = function () {

app.synchronousMode = true;

if (app.document.selectionLength>0) {

    var documento = app.document.selections[0];

    var xmp = documento.synchronousMetadata;

    var instrucao = "" + xmp.read ("http://ns.adobe.com/photoshop/1.0/", "Instructions");

     if (instrucao != "") {

     documento.label = "Adjustments";

   }

}

};

This script is then run from the right mouse menu (context menu)

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
Advocate ,
Dec 19, 2012 Dec 19, 2012

Hi Paul

Thank you a lot. I´ll try your suggestion (but sure it must be preety correct).

I was aware it was the problem (when lauching there are no selected thumbnails). This is why I inserted the entire code into an IF giving the condition ..do it if app.document.selectionLength>0

And this is false when lauching Bridge..so it should not read inside the If. Is my thinking wrong?

Just would like to better understand it

Thank you Paul

Best Regards

Gustavo.

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
Valorous Hero ,
Dec 19, 2012 Dec 19, 2012

Sorry I didn't explain the problem properly. Before you try to access any thumbnail you must wait until the "loaded" event has happened and the script is being run before this event.

Plus the script would only run the once with no way to run it again.

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
Advocate ,
Dec 19, 2012 Dec 19, 2012

Thank you Paul for the explanations

Now it did not get errors on loading. But....

I tried to write instructions to an image and after confirming the entry Bridge did not inserted automatically the blue label...

Do you know if it necessary to insert another line in the code to keep script running and be sensible to any update in any image?

Thank you a lot

Gustavo.

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
Valorous Hero ,
Dec 19, 2012 Dec 19, 2012

Ah, now this is possible, one way would be to check for the "loaded" event then use app.scheduleTask(); to run the script at set intervals.

Or you could use a script with a navbar with a button to stop the script, this would not need the check for a loaded event.

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
Valorous Hero ,
Dec 19, 2012 Dec 19, 2012

As an example of using app.scheduleTask(); and a navbar see...

http://forums.adobe.com/thread/1093857?tstart=30

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
Advocate ,
Dec 19, 2012 Dec 19, 2012

>>Ah, now this is possible, one way would be to check for the "loaded" event then use app.scheduleTask(); to run the script at set intervals.

Or you could use a script with a navbar with a button to stop the script, this would not need the check for a loaded event.

This firt suggestion would be interesting. Is it possible to check for the loaded event every time I write in the Instructions metadata field?

Best Regards

Gustavo.

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
Valorous Hero ,
Dec 19, 2012 Dec 19, 2012

No, the loaded event only happens when you open Bridge or switch to a different folder etc.

The events can be found in the ...

 

Adobe Bridge CS# JavaScript Reference.pdf

This document is found in the Bridge SDK and can be downloaded from :-

http://www.adobe.com/devnet/bridge.html

There isn't an event for an edited thumbnail.

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