Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: xbytor, DavideBarranca, Paul MR



Postby xbytor » Wed Nov 09, 2011 10:53 pm

Here's a bit of code for getting an XMP value out of a document. If it's complex, you have to do a bit more work.
Internally, it handles ISOSpeedRating. For UsageTerms, you could do something like this:

Code: Select all
  var str = getXMPValue(app.activeDocumet, "UsageTerms");
  if (!str) {
  var xml = new XML(str);

  var cr = xml.*::Alt.*::li;
  var terms = cr.toString();

Here's the function:

Code: Select all
// Get the XMP value for (tag) from the object (obj).
// obj can be a String, XML, or Document. Support for
// Files will be added later.
// Based on getXMPTagFromXML from Adobe's StackSupport.jsx
function getXMPValue (obj, tag) {
  var xmp;

  if (obj.constructor == String) {
    xmp = new XML(obj);

  } else if (obj.typename == "Document") {
    xmp = new XML(obj.xmpMetadata.rawData);

  } else if (obj instanceof XML) {
    xmp = obj;

  // } else if (obj instanceof File) {
  // add support for Files

  } else {
    Error.runtimeError(19, "obj");

  var s;
  // Ugly special case
  if (tag == "ISOSpeedRatings") {
    s = String(xmp.*::RDF.*::Description.*::ISOSpeedRatings.*::Seq.*::li);

  }  else {
    s = String(eval("xmp.*::RDF.*::Description.*::" + tag));

  return s;

Return to “Photoshop Scripting: Code Snippets”

Who is online

Users browsing this forum: No registered users and 1 guest