0
writing metadata keywords
New Here
,
/t5/bridge-discussions/writing-metadata-keywords/td-p/1143370
Dec 18, 2005
Dec 18, 2005
Copy link to clipboard
Copied
I've written some scripts that can read and use metadata to do various things but I can't seems to modify the keyword list. When I try to reference the metaData.Keywords that I've succesfully read previously I get an exception. Is this data read only? I've seen lots of folks talk about modifying keywords but no example code.
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143371#M23111
Dec 18, 2005
Dec 18, 2005
Copy link to clipboard
Copied
Dave,
Sorry to say it, but the only metadata you can write using the Metadata Object directly are the simple types (name:value pairs). Keywords are stored as an RDF Bag, and can not be written.
The only way you can write complex types is with the applyMetadataTemplate( template, mode ) method (of the metadata object).
There are two options - first, create templates that contain only the keyword sets you want, then apply them in an "append" mode.
Second: Actually write the template from your script (not that hard to do - take a look at one of the templates - copy the keywords structure as a template, then fill it in with the correct details). Write the template, save it to the templates area, then apply it. If you don't want to clutter up your templates, delete the temporary template file when you're done.
The templates area is
Mac: /[User Lib]/application support/adobe/xmp/metadata templates
PC: c:\documents and settings\[USER]\application data\adobe\xml\metadata templates
Not the best news, but it's a way to get it done. Hope it'll work for you.
Bob
Adobe Workflow Scripting
Sorry to say it, but the only metadata you can write using the Metadata Object directly are the simple types (name:value pairs). Keywords are stored as an RDF Bag, and can not be written.
The only way you can write complex types is with the applyMetadataTemplate( template, mode ) method (of the metadata object).
There are two options - first, create templates that contain only the keyword sets you want, then apply them in an "append" mode.
Second: Actually write the template from your script (not that hard to do - take a look at one of the templates - copy the keywords structure as a template, then fill it in with the correct details). Write the template, save it to the templates area, then apply it. If you don't want to clutter up your templates, delete the temporary template file when you're done.
The templates area is
Mac: /[User Lib]/application support/adobe/xmp/metadata templates
PC: c:\documents and settings\[USER]\application data\adobe\xml\metadata templates
Not the best news, but it's a way to get it done. Hope it'll work for you.
Bob
Adobe Workflow Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143372#M23112
Dec 18, 2005
Dec 18, 2005
Copy link to clipboard
Copied
Hi Dave
You can write keywords in Photoshop - two of my scripts that do this can be found at:
http://www.ps-scripts.com/bb/viewtopic.php?t=53
http://www.ps-scripts.com/bb/viewtopic.php?t=149
The first in very much easier to understand and while it is made for CS it can easily be adapted to CS2 - and could be launched from Bridge using Bridge selections if required.
Andrew
You can write keywords in Photoshop - two of my scripts that do this can be found at:
http://www.ps-scripts.com/bb/viewtopic.php?t=53
http://www.ps-scripts.com/bb/viewtopic.php?t=149
The first in very much easier to understand and while it is made for CS it can easily be adapted to CS2 - and could be launched from Bridge using Bridge selections if required.
Andrew
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143373#M23113
Dec 18, 2005
Dec 18, 2005
Copy link to clipboard
Copied
To add to that, keywords in PS are an array which can be accessed via,
var keys = app.activeDocument.info.keywords;
modified by working with the array, and written to via:
app.activeDocument.info.keywords = keys;
Andrew
var keys = app.activeDocument.info.keywords;
modified by working with the array, and written to via:
app.activeDocument.info.keywords = keys;
Andrew
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_DaveEmerson_
AUTHOR
New Here
,
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143374#M23114
Dec 19, 2005
Dec 19, 2005
Copy link to clipboard
Copied
Thanks for the fast response Bob and Andrew, I'll give these ideas a try.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143375#M23115
Apr 21, 2006
Apr 21, 2006
Copy link to clipboard
Copied
Bob, Andrew,
I just found this thread after bumping into this issue myself. I'd been planning some integration with a controlled vocabulary database for Bridge, building a nice dynamic HTML interface displayed in a modeless dialog in Bridge - I hadn't tried to edit keywords programmatically until last night as I figured that was going to be the easy part!
So it seems there are two options:
1. Open each file in Photoshop for actual keyword assignment
2. Dynamically create metadata templates and then apply them in Bridge
Option 1 sounds impractical, at least for files which don't open/save directly in Photoshop, such as various RAW formats, so I think it's not useful for me.
Option 2 is possible, but seems quite a messy way of doing things, especially as the keyword assignments will be happening incrementally, so I'd be creating a new metadata template each time a user clicks a keyword, as each file a user works with will have an arbitrary mix of keywords, making a more efficient use of metadata templates impossible.
Are there any plans to plug this glaring hole in the Bridge DOM? It seems to me that one of Bridge's main areas of functionality is as a front-end to XMP metadata reading/writing.
Thanks for any thoughts,
Roger Howard
I just found this thread after bumping into this issue myself. I'd been planning some integration with a controlled vocabulary database for Bridge, building a nice dynamic HTML interface displayed in a modeless dialog in Bridge - I hadn't tried to edit keywords programmatically until last night as I figured that was going to be the easy part!
So it seems there are two options:
1. Open each file in Photoshop for actual keyword assignment
2. Dynamically create metadata templates and then apply them in Bridge
Option 1 sounds impractical, at least for files which don't open/save directly in Photoshop, such as various RAW formats, so I think it's not useful for me.
Option 2 is possible, but seems quite a messy way of doing things, especially as the keyword assignments will be happening incrementally, so I'd be creating a new metadata template each time a user clicks a keyword, as each file a user works with will have an arbitrary mix of keywords, making a more efficient use of metadata templates impossible.
Are there any plans to plug this glaring hole in the Bridge DOM? It seems to me that one of Bridge's main areas of functionality is as a front-end to XMP metadata reading/writing.
Thanks for any thoughts,
Roger Howard
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143376#M23116
Sep 29, 2006
Sep 29, 2006
Copy link to clipboard
Copied
Here's a JavaScript snippet I just wrote in order to write keywords into the metadata. It works the way Robert Stuck has suggested as the second option in post #1 in this thread (see above), i. e. it creates a temporary metadata template file and then deletes it after use. It should work on both Macintosh and Windows but I have tested it for Windows only. Here's the code:<br /><br />function SetKeywords(metadata, keywords)<br />{<br /> var strTmpl = "TempTmpl";<br /> var strUser = Folder.userData.absoluteURI;<br /> var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");<br /> var i = 0;<br /> var fResult = false;<br /><br /> try<br /> { if (filTmpl.exists)<br /> filTmpl.remove(); // maybe we should ask the user for permission to delete ...<br /> fResult = filTmpl.open("w");<br /> if (fResult)<br /> { filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");<br /> filTmpl.writeln(" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");<br /> filTmpl.writeln(" <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");<br /> filTmpl.writeln(" <dc:subject>");<br /> filTmpl.writeln(" <rdf:Bag>");<br /> if (keywords != null)<br /> for (i = 0; i < keywords.length; ++i)<br /> filTmpl.writeln(" <rdf:li>", keywords, "</rdf:li>");<br /> filTmpl.writeln(" </rdf:Bag>");<br /> filTmpl.writeln(" </dc:subject>");<br /> filTmpl.writeln(" </rdf:Description>");<br /> filTmpl.writeln(" </rdf:RDF>");<br /> filTmpl.writeln("</x:xmpmeta>");<br /> fResult = filTmpl.close();<br /> metadata.applyMetadataTemplate(strTmpl, "replace");<br /> filTmpl.remove();<br /> } }<br /> catch(e)<br /> { fResult = false; }<br /><br /> return fResult;<br />};<br /><br />Use it like this:<br /><br />var k = Array("Keyword1", "Keyword2", ... "KeywordN"); // an array of strings<br />var t = app.document.thumbnail; // for example<br />var m = t.synchronousMetadata; // metadata object to write the keywords into<br /><br />SetKeywords(m, k);<br /><br />To delete all keywords in m, simply pass the null object as the keyword array, like this:<br /><br />SetKeywords(m, null); // creates the empty keyword set<br /><br />Hope this helps,<br />Olaf
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
LATEST
/t5/bridge-discussions/writing-metadata-keywords/m-p/1143377#M23117
Jun 19, 2009
Jun 19, 2009
Copy link to clipboard
Copied
thanks!
Your script has saved me
Ivan
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

