Copy link to clipboard
Copied
This is my first post to this forum, and first I wish to thank those who provided code snippets to help folks. That also helped me tremendously in getting started with Bridge scripting when documentation was deficient. I have been struggling for days trying to figure out why my script did not update metadata correctly, then narrowed down to some odd behaviors (perhaps it only behaves as I instructed it to do).
0. In Bridge, create a template to add common metadata info such as author info, copyright
1. In Bridge script: Update metadata of an image - event location, headlines etc.; then
2. ApplyMetadataTemplate (append) to the same image to add common fields such as author info and copyright;
Result: Fields added in step 1 were wiped out; some fields identified in the template were added (creator, copyright status and usage terms), but some did not make it (creator state/country/email/website). I had expected that metadata added before applyMetadataTemplate/append would be retained, and all fields specified in the applied template would show up.
I would appreciate any help to show me where I went wrong. Below is a code snippet that illustrates the problem, followed by a diff of metadata dumps before/after ApplyMetadataTemplate command. The test environment: Windows 10, CS6.
var image = "C:/_testBridge/test1.jpg";
var thb = new Thumbnail(image);
var md = thb.synchronousMetadata;
if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile(File(image).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var xmp = xmpf.getXMP();
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "City", 'myCity');
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "State", 'myState');
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Country", 'myCountry');
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.appendArrayItem(XMPConst.NS_DC, "description", 'myDescription', 0, XMPConst.PROP_IS_ARRAY);
xmp.setQualifier(XMPConst.NS_DC, "description[1]", XMPConst.NS_XML, "lang", "x-default");
if (xmpf.canPutXMP(xmp)) {
xmpf.putXMP(xmp);
var xmpObjectInfo = Array;
xmpObjectInfo = xmp.dumpObject();
$.writeln('Applied event metadata to: ', image);
$.writeln(xmpObjectInfo);
}
xmpf.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
//append additional common metadata -author information and copyright
md.applyMetadataTemplate('Test', "append");
var xmpf2 = new XMPFile(File(image).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var xmp2 = xmpf2.getXMP();
xmpObjectInfo = xmp2.dumpObject();
$.writeln('AfterApplyMetadataTemplate-------------------------------------------------------------------------------------------------------------------------');
$.writeln(xmpObjectInfo);
xmpf2.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
Diff result: Fields dropped are highlighted in red; fields added by ApplyMetadataTemplate are highlighted in Green. A large section of the data is omitted.
Dumping XMPMeta object "" (0x0) | Dumping XMPMeta object "" (0x0) | ||
aux: http://ns.adobe.com/exif/1.0/aux/ (0x80000000 : schema) | aux: http://ns.adobe.com/exif/1.0/aux/ (0x80000000 : schema) | ||
... | |||
xmp:ModifyDate = "2015-04-19T13:44:15.00" | xmp:ModifyDate = "2015-04-19T13:44:15.00" | ||
xmp:CreateDate = "2015-04-19T13:44:15.00" | xmp:CreateDate = "2015-04-19T13:44:15.00" | ||
xmp:MetadataDate = "2015-12-08T15:46:42-08:00" | xmp:MetadataDate = "2015-12-10T20:05:51-08:00" | ||
photoshop: http://ns.adobe.com/photoshop/1.0/ (0x80000000 : schema) | photoshop: http://ns.adobe.com/photoshop/1.0/ (0x80000000 : schema) | ||
photoshop:DateCreated = "2015-04-19T13:44:15.00" | photoshop:DateCreated = "2015-04-19T13:44:15.00" | ||
photoshop:Instructions = "Post" | photoshop:Instructions = "Post" | ||
photoshop:City = "myCity" | |||
photoshop:State = "myState" | |||
photoshop:Country = "myCountry" | |||
xmpMM: http://ns.adobe.com/xap/1.0/mm/ (0x80000000 : schema) | xmpMM: http://ns.adobe.com/xap/1.0/mm/ (0x80000000 : schema) | ||
xmpMM:DocumentID = "4FD08D9FEEAAA7FE028B9B7E24CB5925" | xmpMM:DocumentID = "4FD08D9FEEAAA7FE028B9B7E24CB5925" | ||
... | |||
dc: http://purl.org/dc/elements/1.1/ (0x80000000 : schema) | dc: http://purl.org/dc/elements/1.1/ (0x80000000 : schema) | ||
dc:format = "image/jpeg" | dc:format = "image/jpeg" | ||
dc:description (0x200 : isArray) | dc:creator (0x600 : isOrdered isArray) | ||
[1] = "myDescription" (0x50 : hasLang hasQual) | [1] = "Author name field" | ||
? xml:lang = "x-default" (0x20 : isQual) | |||
xmpRights: http://ns.adobe.com/xap/1.0/rights/ (0x80000000 : schema) | xmpRights: http://ns.adobe.com/xap/1.0/rights/ (0x80000000 : schema) | ||
xmpRights:Marked = "True" | xmpRights:Marked = "True" | ||
xmpRights:UsageTerms (0x1E00 : isLangAlt isAlt isOrdered isArray) | |||
[1] = "Usage terms" (0x50 : hasLang hasQual) | |||
? xml:lang = "x-default" (0x20 : isQual) |
Have something to add?