Copy link to clipboard
Copied
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.
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 = ''
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 )…

Copy link to clipboard
Copied
Perfect.
Thank you a lot Muppet.
Will try to write the script then publish where when finishing (or if getting problems).
Best Regards
Gustavo.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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';
};
};
};
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 ) ![]()
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
As an example of using app.scheduleTask(); and a navbar see...
Copy link to clipboard
Copied
>>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.
Copy link to clipboard
Copied
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.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more