What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

Here is an example of setting per layer metadata.

N.B. To use per layer metadata it must be the active layer!

It uses an external library

[code]

setCommentMetadata("This is a comment");


function setCommentMetadata(comm){

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

if( app.activeDocument.activeLayer.isBackgroundLayer){

          alert( "Can not place metadata on a background layer." );

          return;

     }              

 try{

xmp = new XMPMeta( app.activeDocument.activeLayer.xmpMetadata.rawData );

    } catch( e ) {

    xmp = new XMPMeta();

    }

try{

    xmp.setProperty( XMPConst.NS_EXIF, "userComment", comm );

    } catch( e ) {

alert( "Unable to place metadata on selected layer.\n" + e );

          }       

    app.activeDocument.activeLayer.xmpMetadata.rawData = xmp.serialize();

};

[/code]


There is not much difference to get/set of the documents xmp

[code]

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");    

var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);      

xmp.deleteProperty(XMPConst.NS_XMP, "Label");  

xmp.setProperty(XMPConst.NS_XMP, "Label","Approved"); 

app.activeDocument.xmpMetadata.rawData = xmp.serialize();

[/code]


In Photoshop there are a few fields that you can get/set via DOM

[code]

app.activeDocument.info.author

app.activeDocument.info.caption

app.activeDocument.info.captionWriter

app.activeDocument.info.headline

app.activeDocument.info.instructions

app.activeDocument.info.keywords

app.activeDocument.info.author

app.activeDocument.info.authorPosition

app.activeDocument.info.credit

app.activeDocument.info.source

app.activeDocument.info.category

app.activeDocument.info.supplementalCategories

app.activeDocument.info.title

app.activeDocument.info.creationDate

app.activeDocument.info.city

app.activeDocument.info.provinceState

app.activeDocument.info.country

app.activeDocument.info.transmissionReference

app.activeDocument.info.copyrightNotice

app.activeDocument.info.ownerUrl

//Note keywords is an array

app.activeDocument.info.keywords = ["Keyword1","Keyword 2","Etc"];

[/code]


You can access any schema in the document or layer metadata, they are the same. You can also create you own schema, as an example see this old script of mine:-

https://raw.githubusercontent.com/Paul-Riggott/PS-Scripts/master/GuideSets.jsx


Let me know if you want details of get/set without opening a file.

All these methods use the External Library.

You might be able to invoke the library by doing a "doJavaScript" function if it exists in Python?


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top