Skip to main content
Participant
Dec 15, 2017 8:58 PM UTC
Answered

Bring IPTC Keyword field data into Javascript as a string

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 is closed to new replies. Start a new post to keep the conversation going.
Kukurykus
KukurykusCorrect answer
Legend
Dec 15, 2017 10:34 PM UTC

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?

3 replies

Stephen Marsh
Community Expert
Community Expert
Dec 16, 2017 7:55 AM UTC

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
Dec 15, 2017 10:34 PM UTC

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?

Translate
Participant
Dec 16, 2017 10:38 AM UTC

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

Translate