Skip to main content
Participant
December 15, 2017
Answered

Bring IPTC Keyword field data into Javascript as a string

  • December 15, 2017
  • 2 replies
  • 1436 views

Hi Everyone,

Wondering if anyone can help me. I have some keywords saved in the images IPTC metadata, I'm running a script to which will run different actions on images based on sections of filenames, which works fine. But I want to be able to bring in those keywords from iptc and use those to decide on the actions.

I there any way to bring IPTC data into Javascript as a string? I can do it with normal exif data but I cant for the life of me work this one out.

Thanks in advance!

Richard

This topic has been closed for replies.
Correct answer Kukurykus

Some are available by Photoshop scripting. For example:

activeDocument.info.keywords

You can also combine regex with result of:

activeDocument.xmpMetadata.rawData

In that second case doeument must be saved.

What fields exaclty you want to read?

2 replies

Stephen Marsh
Community Expert
Community Expert
December 16, 2017

I can’t script, however I am guessing that you may need DC:Subject rather than IPTC:Keyword metadata.

This conditional action script does what you require:

Siva's Photoshop Conditional Action: Siva's Photoshop Conditional Action

As does this script:

https://forums.adobe.com/thread/2314586

As an example, if the keyword was “key1” (line 10 below), then run a Photoshop action titled “Molten Lead” in the set “Default Actions” (line 12 below). The action obviously needs to be loaded first, not sure if you can script to ensure that this is the case or not:

#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 

        app.doAction("Molten Lead","Default Actions.atn") 

        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; 

};

Kukurykus
KukurykusCorrect answer
Legend
December 15, 2017

Some are available by Photoshop scripting. For example:

activeDocument.info.keywords

You can also combine regex with result of:

activeDocument.xmpMetadata.rawData

In that second case doeument must be saved.

What fields exaclty you want to read?

Participant
December 16, 2017

Thanks so much for this. That's exactly what I needed. Worked straight away.