Skip navigation
DonJohnston
Currently Being Moderated

Combining data from iptc fields

Jan 12, 2012 5:52 AM

Tags: #bridge #batch #to #metadata #fields #scripts

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

 
Replies
  • Currently Being Moderated
    Jan 12, 2012 9:18 AM   in reply to DonJohnston

    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); 
            }
        }
    }
    
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 12, 2012 11:11 AM   in reply to DonJohnston

    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);}
        }
    }
    
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 12, 2012 12:11 PM   in reply to DonJohnston

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 12, 2012 12:41 PM   in reply to DonJohnston

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

     

    All the very best.

    Paul.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points