Batch append a single keyword

AL
Posted By
Adrian_Lambert
Feb 11, 2009
Views
424
Replies
10
Status
Closed
We enter keywords using Photo Mechanic when ingesting, but would like to add one to files processed from raw using the batch utility or a script.
In File Info you can append a keyword, but if you record this step for an action it translates as set keyword to "x". Therefore it removes all the other keywords.
Can anyone help or point me to a script that can be ran from within the batch? many thanks

Must-have mockup pack for every graphic designer πŸ”₯πŸ”₯πŸ”₯

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

R
Ram
Feb 11, 2009
Adrian,

It would be useful to know what software you use or want to use, i.e. exact version of Photoshop, Bridge, and the OS.

CLICK HERE <http://www.adobeforums.com/webx?50@@.2cd06cd9> for advice on how to ask your question correctly for quicker answers. Thanks!

Also, have you investigated Bridge metadata templates?
AL
Adrian_Lambert
Feb 11, 2009
OK!
CS3 and CS4 both on Mac Pro 2.67Ghz with stock video cards. Plenty of disk space and about 6GB Ram on each Workstation….
I haven’t looked too much into bridge as I want to integrate this extra keyword into our already extended list of steps for our workflow.
After we’ve processed in Capture One we open in PS for a bit of spit and polish. We save the files, and when the folder is done we drop it onto one of several droplets depending on which photographer shot the images, and what they are being used for. The droplet action places a ‘digital slide mount’ around the image with a bit of Β© info and saves the finished file out as a jpeg at Q11.
PR
Paul_R
Feb 11, 2009
I don’t think it can be done, well not in Photoshop CS4 maybe with CS4 as that has access to the metadata. If you need to have it working for both CS3 and CS4 you would need to have Bridge open so that the keyword list could be fetched.
You can add keywords using templates but append only works in CS4 but then it does not work via an action.
Options use a script just for CS4 or have bridge running and use script that should work on both. Anyway I’m sure someone will come up with a solution.
Here is a script that I’ve just tested on CS3 that will append a keyword. Change MyNewKey var to suit.

#target photoshop

//////////////////////////////////////////////////////////// //////////////////////////

MyNewKey= "EnterYourNewKeywordHere";

//////////////////////////////////////////////////////////// /////////////////////////

BridgeTalk.prototype.sendSynch = function(timeout) {

var self = this;

self.onResult = function(res) {

this.result = res.body;

this.complete = true;

}

self.complete = false;

self.send();

if (timeout) {

for (var i = 0; i < timeout; i++) {

BridgeTalk.pump();

if (!self.complete) {

$.sleep(1000);

} else {

break;

}

}

}

var res = self.result;

self.result = self.complete = self.onResult = undefined;

return res;

};

function getKeys() {

var bridgeApp = "bridge";

if (!BridgeTalk.isRunning(bridgeApp)) {

BridgeTalk.launch(bridgeApp);

}

var bt = new BridgeTalk();

bt.target = bridgeApp;

bt.body = "function z(){var f = new Thumbnail(‘"+activeDocument.fullName.fsName+"’); var md = f.synchronousMetadata;"+

"md.namespace = ‘http://ns.adobe.com/photoshop/1.0/‘; var result = md.Keywords;return result;}z();";

var res = bt.sendSynch(10);

addKeyWord(res,MyNewKey)

};

function addKeyWord(Keys,newKey) {

var desc19 = new ActionDescriptor();

var ref8 = new ActionReference();

ref8.putProperty( charIDToTypeID(‘Prpr’), charIDToTypeID(‘FlIn’) );

ref8.putEnumerated( charIDToTypeID(‘Dcmn’), charIDToTypeID(‘Ordn’), charIDToTypeID(‘Trgt’) );

desc19.putReference( charIDToTypeID(‘null’), ref8 );

var desc20 = new ActionDescriptor();

var list3 = new ActionList();

Keys=Keys.split(‘,’);

for(var a=0;a<Keys.length;a++){

list3.putString( Keys[a].toString() );

}

list3.putString( newKey);

desc20.putList( charIDToTypeID(‘Kywd’), list3 );

desc19.putObject( charIDToTypeID(‘T ‘), charIDToTypeID(‘FlIn’), desc20 );

executeAction( charIDToTypeID(‘setd’), desc19, DialogModes.NO );

};

getKeys();
PR
Paul_R
Feb 11, 2009
Just thought of another way without using Bridge, that is to use the rawdata and extract the existing keywords and feed them into addKeyWord function, that should work for CS2/3 and 4.
The only problem is extracting the keywords, my codeing with xml is not good. If I get chance I will have a play.
R
Ram
Feb 11, 2009
stock video cards. Plenty of disk space

Β…which tells us nothing. πŸ™

However, since Paul says it can’t be done, it’s a moot point.
PR
Paul_R
Feb 11, 2009
Here we are done and working, tested in Photoshop CS2/3 and 4 It will append a keyword to the active document.

#target photoshop

///////////////////////////////////////////////////////////

//Put your new keyword below.

newKey = "TestKeyWord";

///////////////////////////////////////////////////////////

var xmp = activeDocument.xmpMetadata.rawData;

xmp=xmp.substr(xmp.search("subject")+ 8 );

xmp=xmp.substr(0,xmp.search("subject")-5);

var keyList =[];

for(var a=0;a<10;a++){

var key=”;

key =parseMetadata(xmp, ‘rdf:li’);

if(key == ”)break;

xmp=xmp.substr(xmp.search("/rdf")+7);

if(key != ”) keyList.push(key);

}

addKeyWord(keyList.toString(),newKey);

function parseMetadata(xmp, tag) {

var re = new RegExp(‘<‘ + tag + ‘>(.+)</’ + tag + ‘>’);

var m = xmp.match(re);

if (!m) {

re = new RegExp("<[^:]+:" + tag + ">(.+)</[^:]+:" + tag + ‘>’);

m = this.xmp.match(re);

}

return (m ? m[1] : ”);

};

function addKeyWord(Keys,newKey) {

var desc19 = new ActionDescriptor();

var ref8 = new ActionReference();

ref8.putProperty( charIDToTypeID(‘Prpr’), charIDToTypeID(‘FlIn’) );

ref8.putEnumerated( charIDToTypeID(‘Dcmn’), charIDToTypeID(‘Ordn’), charIDToTypeID(‘Trgt’) );

desc19.putReference( charIDToTypeID(‘null’), ref8 );

var desc20 = new ActionDescriptor();

var list3 = new ActionList();

Keys=Keys.split(‘,’);

for(var a=0;a<Keys.length;a++){

list3.putString( Keys[a].toString() );

}

list3.putString( newKey);

desc20.putList( charIDToTypeID(‘Kywd’), list3 );

desc19.putObject( charIDToTypeID(‘T ‘), charIDToTypeID(‘FlIn’), desc20 );

executeAction( charIDToTypeID(‘setd’), desc19, DialogModes.NO );

};
AL
Adrian_Lambert
Feb 11, 2009
Wow Paul! I’m in Australia, so I just awoke to see this! Thanks very much indeed, I hope others can benefit too but this will be very useful for me. I’m not going to have a chance to put it into the batch until tomorrow, but I’ll get back to you with my experience.

Ramon. thanks to you too. Your contribution was invaluable.
PR
Paul_R
Feb 11, 2009
No problem Adrian, bedtime here in the UK.
Just noticed there could be a problem if no keyword existed. This version should be better….

#target photoshop

///////////////////////////////////////////////////////////

//Put your new keyword below.

newKey = "TestKeyWord";

///////////////////////////////////////////////////////////

var xmp = activeDocument.xmpMetadata.rawData;

xmp=xmp.substr(xmp.search("subject")+ 8 );

xmp=xmp.substr(0,xmp.search("subject")- 5 );

var keyList =[];

for(var a=0;a<100;a++){

var key=”;

key =parseMetadata(xmp, ‘rdf:li’);

if(key == ”)break;

xmp=xmp.substr(xmp.search("/rdf")+ 7 );

if(key != ”) keyList.push(key);

}

addKeyWord(keyList.toString(),newKey);

function parseMetadata(xmp, tag) {

var re = new RegExp(‘<‘ + tag + ‘>(.+)</’ + tag + ‘>’);

var m = xmp.match(re);

if (!m) {

re = new RegExp("<[^:]+:" + tag + ">(.+)</[^:]+:" + tag + ‘>’);

m = this.xmp.match(re);

}

return (m ? m[1] : ”);

};

function addKeyWord(Keys,newKey) {

var desc19 = new ActionDescriptor();

var ref8 = new ActionReference();

ref8.putProperty( charIDToTypeID(‘Prpr’), charIDToTypeID(‘FlIn’) );

ref8.putEnumerated( charIDToTypeID(‘Dcmn’), charIDToTypeID(‘Ordn’), charIDToTypeID(‘Trgt’) );

desc19.putReference( charIDToTypeID(‘null’), ref8 );

var desc20 = new ActionDescriptor();

var list3 = new ActionList();

if (Keys.length>0){Keys=Keys.split(‘,’);

for(var a=0;a<Keys.length;a++){

list3.putString( Keys[a].toString() );

}}

list3.putString( newKey);

desc20.putList( charIDToTypeID(‘Kywd’), list3 );

desc19.putObject( charIDToTypeID(‘T ‘), charIDToTypeID(‘FlIn’), desc20 );

executeAction( charIDToTypeID(‘setd’), desc19, DialogModes.NO );

};
AL
Adrian_Lambert
Feb 12, 2009
….and bug fixes before I’ve even tested it! Thanks again Paul.
R
Ram
Feb 12, 2009
Adrian,

Hope you’re safe and away from those fires.

MacBook Pro 16” Mockups πŸ”₯

– in 4 materials (clay versions included)

– 12 scenes

– 48 MacBook Pro 16″ mockups

– 6000 x 4500 px

Related Discussion Topics

Nice and short text about related topics in discussion sections