10 Replies Latest reply: Jan 12, 2012 12:44 PM by DonJohnston RSS

    Combining data from iptc fields

    DonJohnston Community Member

      Hello group. Happy New Year.

       

      I'm looking for a script which would perform an action of copying data from the city, state/prov and country fields and adding that data to the description field. I still wish to retain the content in the description field. My stock agency is requesting this be done in order to create a more complete picture caption for web display.

       

      Hoping the list can help! Thanks

       

      Don

        • 1. Re: Combining data from iptc fields
          Paul Riggott Community Member

          Happy new year Don, hope you have a good one!

           

          Please try this...

           

           

          #target bridge   
          if( BridgeTalk.appName == "bridge" ) {  
          combineFields = MenuElement.create("command", "Details to Description", "at the end of Tools","cft2012");
          }
          combineFields.onSelect = function () { 
          if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
          var sels = app.document.selections;
          for(var z in sels){
          var t = new Thumbnail(sels[z]);    
          var md = t.synchronousMetadata
          var Desc = md.read("http://purl.org/dc/elements/1.1/",  "dc:description");
          var City = md.read("http://ns.adobe.com/photoshop/1.0/",  "City");
          var Country = md.read("http://ns.adobe.com/photoshop/1.0/",  "Country");
          var Region =  md.read("http://ns.adobe.com/photoshop/1.0/",  "State");
          var DescAll = Desc + "\r" +City + "\r" + Region +"\r" + Country;    
          var myXmpFile = new XMPFile( t.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
          var myXmp = myXmpFile.getXMP();
          myXmp.deleteProperty(XMPConst.NS_DC, "description"); 
          myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", DescAll ); 
          if (myXmpFile.canPutXMP(myXmp)) { 
                  myXmpFile.putXMP(myXmp);
                   myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
                  }
              }
          }
          
          
          • 2. Re: Combining data from iptc fields
            DonJohnston Community Member

            Hi Paul

             

            Many thanks!

             

            Please bear with me regarding getting this script going. I copied your code and pasted it into ExtendScript Toolkit in Adobe utilities CS5. I gave it a name and saved it to my Bridge Scripts folder. When I restarted Bridge i was asked if I wished to enable this script, so things looked good so far.

             

            But when I tried it on a nef file which contained info in the relevant fields nothing happened, so I don't know whether there is a bug in the script or whether I missed doing something trying to apply it. I clicked on a file and then I clicked on the script which now appears in the Tools window, but the info in the Description field remained the same.

             

            What am I missing?

             

            Hope 2012 is off to a great start for you!

             

            Don

            • 3. Re: Combining data from iptc fields
              DonJohnston Community Member

              Hi Paul

               

              OK, I tried it on a tif file and it worked! Great stuff. Many thanks again.

               

              Don

              • 4. Re: Combining data from iptc fields
                Paul Riggott Community Member

                Sorry about that Don, NEF files are a pain in the backside

                 

                Hopefully this code will work for NEF file only!

                It update the xmp file so after it has run you would need to refreash the folder (or select a diffirent folder and go back)

                 

                 

                #target bridge   
                if( BridgeTalk.appName == "bridge" ) {  
                combineFields2 = MenuElement.create("command", "NEF Details to Description", "at the end of Tools","cfta2012");
                }
                combineFields2.onSelect = function () { 
                if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
                var sels = app.document.selections;
                for(var z in sels){
                var Name = decodeURI(sels[z].spec.name).replace(/\.[^\.]+$/, ''); 
                var file = File(sels[z].spec.path + "/" + Name +".xmp");
                if(file.exists){
                     file.open('r');
                     file.encoding = "UTF8";
                     file.lineFeed = "unix"; 
                     file.open("r", "TEXT", "????");
                     var xmpStr = file.read();
                     file.close();
                     }else{
                         var xmpStr='';
                         }
                     var xmp = new XMPMeta( xmpStr );
                var arrItem=[];
                var items = xmp.countArrayItems(XMPConst.NS_DC, "description");
                for(var i = 1;i <= items;i++){
                 arrItem.push(xmp.getArrayItem(XMPConst.NS_DC, "description", i));
                }
                try{
                var Desc = arrItem.toString();
                var City = xmp.getProperty(XMPConst.NS_PHOTOSHOP, "City");
                var Country = xmp.getProperty(XMPConst.NS_PHOTOSHOP, "Country");
                var Region =  xmp.getProperty(XMPConst.NS_PHOTOSHOP,  "State");
                var DescAll = Desc + "\r" +City + "\r" + Region +"\r" + Country;    
                xmp.deleteProperty(XMPConst.NS_DC, "description"); 
                xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", DescAll ); 
                file.open('w');
                     file.encoding = "UTF8";
                     file.lineFeed = "unix"; 
                     file.write( xmp.serialize() );
                     file.close();
                     }catch(e){alert(e+"-"+e.line);}
                    }
                }
                
                
                • 5. Re: Combining data from iptc fields
                  DonJohnston Community Member

                  Hi Paul

                   

                  In retrospect I think it will work best with the tif files. Sorry to make you do the extra work for the nefs. I'll install it anyway, and I might find it useful going forward.

                   

                  With respect to the first script (for the tif files) would it be possible to modify it so that the extra data is not on separate lines, rather it is all continuous. I expect there won't be punctuation marks, although I could add commas at the end of each field entry, but with capitals starting each entry I think a reader will follow the data path. I'm guessing (haven't heard back from my agency yet) that they will prefer the data to be in one continuous line.

                   

                  Please advise.

                   

                  Don

                  • 6. Re: Combining data from iptc fields
                    Paul Riggott Community Member

                    It might be best to use commas to separate the different fields Don.

                    This version appends each field with a comma and space between them ...

                     

                     

                    #target bridge   
                    if( BridgeTalk.appName == "bridge" ) {  
                    combineFields = MenuElement.create("command", "Details to Description", "at the end of Tools","cft2012");
                    }
                    combineFields.onSelect = function () { 
                    if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
                    var sels = app.document.selections;
                    for(var z in sels){
                    var t = new Thumbnail(sels[z]);    
                    var md = t.synchronousMetadata
                    var Desc = md.read("http://purl.org/dc/elements/1.1/",  "dc:description");
                    var City = md.read("http://ns.adobe.com/photoshop/1.0/",  "City");
                    var Country = md.read("http://ns.adobe.com/photoshop/1.0/",  "Country");
                    var Region =  md.read("http://ns.adobe.com/photoshop/1.0/",  "State");
                    var DescAll = Desc + ", " +City + ", " + Region +", " + Country;    
                    var myXmpFile = new XMPFile( t.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
                    var myXmp = myXmpFile.getXMP();
                    myXmp.deleteProperty(XMPConst.NS_DC, "description"); 
                    myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", DescAll ); 
                    if (myXmpFile.canPutXMP(myXmp)) { 
                            myXmpFile.putXMP(myXmp);
                             myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
                            }
                        }
                    }
                    
                    

                     

                     

                    The line that you might want to alter is ..

                     

                    var DescAll = Desc + ", " +City + ", " + Region +", " + Country;  
                     
                    

                    If you don't want the commas you could remove them just leaving a space.

                    • 7. Re: Combining data from iptc fields
                      DonJohnston Community Member

                      Hi Paul

                       

                      I'll test that out shortly. Thanks a ton. I'll try that line variation and report back soon.

                       

                      Best

                       

                      Don

                      • 8. Re: Combining data from iptc fields
                        DonJohnston Community Member

                        Yes, the commas work well. I think the script will be exactly what I need.

                         

                        My best to you and your family.

                         

                        btw Check out this on line article. The text and description has been embellished somewhat but I had not control over that. I was contacted by Caters News Agency about some of my polar bear pictures and this is the first result, picked up by the Mail On Line. I chided them about not including my name in the copyright and my contact said that was an oversight by the Mail. Anyway

                         

                        http://www.dailymail.co.uk/news/article-2082632/You-left-paw-right-paw-Dancing-ice-Polar-b ear-way.html?ito=feeds-newsxml

                         

                        Cheers

                         

                        Don

                        • 9. Re: Combining data from iptc fields
                          Paul Riggott Community Member

                          Fantastic pictures Don, I would have loved to have been there with my camera!

                           

                          All the very best.

                          Paul.

                          • 10. Re: Combining data from iptc fields
                            DonJohnston Community Member

                            Hi Paul

                             

                            I just realized that the agency works with jpegs but I see your revised script also works with jpegs which I just tested, which is excellent.

                             

                            Don