view/edit raw xmp data in Bridge?

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

Patrick

view/edit raw xmp data in Bridge?

Post by Patrick »

I had this snippit of code that someone posted on here awhile back to view the full XMP data for an image in PS:

Code: Select allvar xmp = app.activeDocument.xmpMetadata;
var fullstring = xmp["rawData"].toString();

Unfortunately, this same code does not work in Bridge. Does anyone know if it is possible to pull this info up from within Bridge? I am trying to remove keywords, and it looks like the only way this can be done inside Bridge would be to edit the raw XMP. The other option would be via exiftool by way of .bat file, trying to avoid that if possible though. Any ideas would be appreciated!

Patrick
Mike Hale

view/edit raw xmp data in Bridge?

Post by Mike Hale »

Hi Patrick,

As I understand it you can read keywords, but can't write them directly with a script.

You can add/remove keywords with a script using a metadata template.

If you just want to clear the existing keywords you can use the blank keyword template below.

Code: Select all<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1.1-111">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <dc:creator>
            <rdf:Seq>
               <rdf:li>m</rdf:li>
            </rdf:Seq>
         </dc:creator>
         <dc:subject>
            <rdf:Bag>
               <rdf:li> </rdf:li>
            </rdf:Bag>
         </dc:subject>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>


The above will only clear the keywords when used in replace mode. It will leave all the other metadata intact.

Mike
Mike Hale

view/edit raw xmp data in Bridge?

Post by Mike Hale »

Or even better, here is a post from the Adobe Bridge forum by Olaf Ulrich last Sept.

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:

function SetKeywords(metadata, keywords)
{
var strTmpl = "TempTmpl";
var strUser = Folder.userData.absoluteURI;
var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");
var i = 0;
var fResult = false;

try
{ if (filTmpl.exists)
filTmpl.remove(); // maybe we should ask the user for permission to delete ...
fResult = filTmpl.open("w");
if (fResult)
{ filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");
filTmpl.writeln(" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");
filTmpl.writeln(" <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");
filTmpl.writeln(" <dc:subject>");
filTmpl.writeln(" <rdf:Bag>");
if (keywords != null)
for (i = 0; i < keywords.length; ++i) filTmpl.writeln(" <rdf:li>", keywords, "</rdf:li>");
filTmpl.writeln(" </rdf:Bag>");
filTmpl.writeln(" </dc:subject>");
filTmpl.writeln(" </rdf:Description>");
filTmpl.writeln(" </rdf:RDF>");
filTmpl.writeln("</x:xmpmeta>");
fResult = filTmpl.close();
metadata.applyMetadataTemplate(strTmpl, "replace");
filTmpl.remove();
} }
catch(e)
{ fResult = false; }

return fResult;
};

Use it like this:

var k = Array("Keyword1", "Keyword2", ... "KeywordN"); // an array of strings
var t = app.document.thumbnail; // for example
var m = t.synchronousMetadata; // metadata object to write the keywords into

SetKeywords(m, k);

To delete all keywords in m, simply pass the null object as the keyword array, like this:

SetKeywords(m, null); // creates the empty keyword set

Hope this helps,
Olaf