Copy link to clipboard
Copied
Hi all,
I am used to scripting but i am new in photoshop javascript.
I need to set up a script to open an undefined number of camera raw images (CR2) and apply different actions based on some xmp data (in example, depending on the presence or abscense of a specific "keyword" in the xmp data)
Can anyone help me? maybe a clue about how to read the xmp data of the CR2 file? I am sure this must be a very simple script but I feel lost with the information I read in the forums.
Thanks a lot!
It seems you want the metadata when a file is opened in Photoshop, if so here are the basics...
...#target photoshop;
if(documents.length){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
var shadow = xmp.getProperty(XMPConst.NS_CAMERA_RAW,"ParametricShadowSplit");
var exposureValue = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Exposure");
var keys = getArrayItems(XMPConst.NS
Copy link to clipboard
Copied
[Question moved to the PS Scripting forum]
Copy link to clipboard
Copied
Yes, it would be possible. You would have to find the correct syntax for displaying the keywords in the metadata. I've done a little with with metadata, and it drives me nuts trying to figure out the correct syntax and namespaces to use. You might want to ask you question in the XMP SDK forum: XMP SDK
Copy link to clipboard
Copied
There are Photoshop posted on the web the parse EXIF metadata. You could download them and look ate the code. I would think that Paul Riggott's "Metadata" scripts would be also be a good ones to look at. He is an expert scripter GitHub - Paul-Riggott/PS-Scripts: Photoshop Scripts
Be careful it you insert and remove move data in a metadata field Adobe intentionally broke Photoshop scripting in CC 2015.5. If removing your data would result in the metadata field becoming empty again. Photoshop will no remove your data as of this change.
Photoshop CC 2015.5: Script Metadata assigment error | Photoshop Family Customer Community
Copy link to clipboard
Copied
It seems you want the metadata when a file is opened in Photoshop, if so here are the basics...
#target photoshop;
if(documents.length){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
var shadow = xmp.getProperty(XMPConst.NS_CAMERA_RAW,"ParametricShadowSplit");
var exposureValue = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Exposure");
var keys = getArrayItems(XMPConst.NS_DC,'subject');
for(var a in keys){
//amend the match for your keywod
if(keys.toString().match(/key1/)){
//things to do if keyword found
alert("keyword found");
break;
}
}
};
function getArrayItems(ns, prop){
var arrItem=[];
var items = xmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(xmp.getArrayItem(ns, prop, i));
}
return arrItem;
};
Copy link to clipboard
Copied
I was going to suggest the following script:
Siva's Photoshop Conditional Action: Siva's Photoshop Conditional Action
However I was not having much luck with getting it to work as intended.
Adding to SuperMerlin’s post (replacing line #12):
app.doAction("My Action","My Action Set.atn")
Copy link to clipboard
Copied
MetaData is a convenient place to store information for the different document you are currently working when you switch between documents you use data relative to the active document. Scripts can insert and remove information they can use future executions or instruction to be used by other scripts. I do this in several of my script and I chose to use the meta-data field instruction. My scripts all use that metadata filed they carefully insert and remove their data in the instructions they preserve any other data there. Adobe broke that in CC 2015.5.
Copy link to clipboard
Copied
Awesome guys, the solution of SuperMerlin worked perfect