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
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);
}
}
}
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
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);}
}
}
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
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.
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
Cheers
Don
North America
Europe, Middle East and Africa
Asia Pacific