3 Replies Latest reply on Dec 16, 2017 2:38 AM by richardj70509445

    Bring IPTC Keyword field data into Javascript as a string

    richardj70509445

      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

        • 1. Re: Bring IPTC Keyword field data into Javascript as a string
          Kukurykus Adobe Community Professional

          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 people found this helpful
          • 2. Re: Bring IPTC Keyword field data into Javascript as a string
            Stephen_A_Marsh Adobe Community Professional

            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[a].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;  
            };
            
            1 person found this helpful
            • 3. Re: Bring IPTC Keyword field data into Javascript as a string
              richardj70509445 Level 1

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