// MAIN CODE: // Load the XMPScript library and check to ensure the user has selected an image frame if(loadXMPLibrary() && app.selection.length == 1 && app.selection[0].contentType == ContentType.GRAPHIC_TYPE){ // get the filepath to the image and then create a XMPFile object to access the embedded metadata directly var myFile = File(app.selection[0].graphics[0].itemLink.filePath); xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ); // set variable to include entire XMP from the image file var myXmp = xmpFile.getXMP(); xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); // Unload the XMPScript library and close the object unloadXMPLibrary(); } // check for the existance of the XMP data and setup variable info using namespace/property info if(myXmp){ var myCreatorTool = myXmp.getProperty(XMPConst.NS_XMP,"CreatorTool"); var myLocation = myXmp.getProperty(XMPConst.NS_IPTC_CORE,"Location"); var mySubject = myXmp.getArrayItem(XMPConst.NS_DC,'subject',1); var keywords = getArrayItems("http://ns.adobe.com/lightroom/1.0/","hierarchicalSubject"); // Setup a warning box to display the restuls alert("XMP LR Hierarchical Keywords: " + keywords); // Create a text frame and add the keyword info var doc = app.activeDocument; var textFrame = doc.pages[0].textFrames.add(); textFrame.properties = { //DESCRIPTION:Show geometricBounds (y1, x1, y2, x2) geometricBounds : [ 7,0.5,8,7.75 ], strokeWidth : 0, contents : "XMP LR Hierarchical Keywords: " + keywords, fillColor : "None"}; } // FUNCTIONS: // Load AdobeXMPScript Library function loadXMPLibrary(){ if ( !ExternalObject.AdobeXMPScript ){ try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');} catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;} } return true; } // UnLoad AdobeXMPScript Library function unloadXMPLibrary(){ if( ExternalObject.AdobeXMPScript ){ try{ExternalObject.AdobeXMPScript.unload(); ExternalObject.AdobeXMPScript = undefined;} catch (e){alert('Unable to unload the AdobeXMPScript library!');} } } // Write the selected image XMP information to a file for examination function writeXMP(xmpData, xmpFile){ xmpFile.open ( 'w', 'Text'); xmpFile.encoding = 'UTF-8'; xmpFile.write (xmpData); xmpFile.close (); } // Loop through a Namespace and Property to array items with multiple data entries function getArrayItems(ns, prop){ var arrItem=[]; var items = myXmp.countArrayItems(ns, prop); for(var i = 1;i <= items;i++){ arrItem.push(myXmp.getArrayItem(ns, prop, i)); } return arrItem; };