Check if Pathitem exists and set Metadata accordingly

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

djonyx

Check if Pathitem exists and set Metadata accordingly

Post by djonyx »

Hi there,

i'm a complete newbie to PS-Scripting and have a problem to solve. Hopefully someone can help me on this:

i am handing Jpeg-Files to PhotoshopCS4 with Enfocus Powerswitch on a Macintosh, then the Script has to check if there is a Pathitem called "Path 1". On success a new Metadatafield called "Path 1" of Type "Boolean" has to be created and set to "1" and the Action "W-S-Path" from Action-Set "SWITCH" has to be called. On failure a new Metadatafield called "Path 1" of Type "Boolean" has to be created and set to "0".
I hope that its possible to get that done somehow, as i have no clue

Thanks in advance.

patrick

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Paul MR

Check if Pathitem exists and set Metadata accordingly

Post by Paul MR »

You can't have a metadata field with a space in it, so this uses Path_1 ...

Code: Select allmain();
function main(){
if(!documents.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var psNamespace = "http://ns.pathInfo/1.0/";
var psPrefix = "path:";
XMPMeta.registerNamespace(psNamespace, psPrefix);
xmp = new XMPMeta( app.activeDocument.xmpMetadata.rawData );
xmp.deleteProperty(psNamespace, "Path_1");
try{
var path = activeDocument.pathItems["Path 1"];
xmp.setProperty(psNamespace, "Path_1",1);
app.doAction("W-S-Path" , "SWITCH");
}catch(e){
    xmp.setProperty(psNamespace, "Path_1",0);
}
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
djonyx

Check if Pathitem exists and set Metadata accordingly

Post by djonyx »

Hi Paul,

Many thanks for your quick reply and your script! I'll try it immediately and let you know the results!
this looks great!
djonyx

Check if Pathitem exists and set Metadata accordingly

Post by djonyx »

Hi Paul,

you made my day, works like a charm!
Thanks a lot and have a nice day!

patrick
jschober

Check if Pathitem exists and set Metadata accordingly

Post by jschober »

Is it possible to change the script that it checks if any path exists or not?

Kind regards,
Jörg
Paul MR

Check if Pathitem exists and set Metadata accordingly

Post by Paul MR »

Yes, you could do something like this...

Code: Select allmain();
function main(){
if(!documents.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var psNamespace = "http://ns.pathInfo/1.0/";
var psPrefix = "path:";
XMPMeta.registerNamespace(psNamespace, psPrefix);
xmp = new XMPMeta( app.activeDocument.xmpMetadata.rawData );
xmp.deleteProperty(psNamespace, "Path_1");
if(activeDocument.pathItems.length >0){
xmp.setProperty(psNamespace, "Path_1",1);
//amend action to suit
//app.doAction("W-S-Path" , "SWITCH");
}else{
    xmp.setProperty(psNamespace, "Path_1",0);
}
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
jschober

Check if Pathitem exists and set Metadata accordingly

Post by jschober »

Thanks! Works fine!