Copy link to clipboard
Copied
Hi Folks,
In a JavaScript in Bridge CS3, I'm updating a value in the XMP metadata for a Thumbnail. Later in the script I want to read the updated XMP metadata information from the Thumbnail, but often Bridge hasn't updated the metadata by the time I read it. In other words, my script reads the value prior to the update. I'm guessing there's a caching issue going on.
I'm new to Bridge scripting, and I am hoping someone here can offer suggestions on how I can (or, even *if* I can) force Bridge to update the XMP metadata cache for a file so that when I read it later in the script it will reflect the recent changes. I've tried using Thumbnail.refresh(), but that doesn't seem to do the trick. I don't mind a slower script, I just want to be able to read the correct value.
Thanks in advance for any help!
-- Jim
Where you have the line
thumb.metadata = new Metadata(updatedPacket);
Try
app.synchronousMode = true;
thumb.metadata = new Metadata(updatedPacket);
app. synchronousMode = false;
By default Bridge's metadata updates happen in the background and not on the main thread, but by using synchronous mode here your script won't continue to the next line until the operation is complete.
-David
Copy link to clipboard
Copied
If you can post a short, example script and test file that demonstrates the problem, I think that would help us answer the question. And by short I mean the shortest script you can write that still produces the problem.
Thanks,
David
Copy link to clipboard
Copied
Hi David,
I'm running this script on a MacBook Pro, 2.5GHz, 4GB RAM.
Here is a sample JSX that shows the issue I'm having:
#target "bridge-2.0"
main();
function main() {
if( xmpLib == undefined ) {
var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.framework";
var libfile = new File( pathToLib );
var xmpLib = new ExternalObject("lib:" + pathToLib );
}
var myValue = "Headline Test";
var myFilePath = "~/Desktop/TestFile.tif";
var curHeadlineStr = XMPGetHeadline(myFilePath);
$.writeln("Headline value: \"" + curHeadlineStr + "\"");
XMPWriteHeadline(myFilePath, myValue);
// *** I would like to refresh the cache here ***
curHeadlineStr = XMPGetHeadline(myFilePath);
$.writeln("Headline value: \"" + curHeadlineStr + "\"");
}
function XMPGetHeadline(theFilePath) {
var thumb = new Thumbnail(File (theFilePath) );
md = thumb.synchronousMetadata;
xmp = new XMPMeta(md.serialize());
var myHeadlineXMPProp = xmp.getProperty
(XMPConst.NS_PHOTOSHOP, "Headline", XMPConst.STRING);
return myHeadlineXMPProp;
}
function XMPWriteHeadline(theFilePath, theTextStr){
var thumb = new Thumbnail(File (theFilePath) );
md = thumb.synchronousMetadata;
xmp = new XMPMeta(md.serialize());
var myOrigHeadlineXMPProp = xmp.getProperty
(XMPConst.NS_PHOTOSHOP, "Headline", XMPConst.STRING);
xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Headline");
xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Headline", theTextStr, 0, XMPConst.STRING);
var updatedPacket = xmp.serialize
(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
thumb.metadata = new Metadata(updatedPacket);
}
To run this script, in main(), set the myFilePath variable to the path of a file that has an "IPTC Code" "Headline" property.
This script, when run, sets the "Headline" property value to the value of myValue. After runing the script for the first time, take a look at the console log. You should see that Headline value displayed does not change between the two console entries. My log looks like this after the first run:
Headline value: "undefined"
Headline value: "undefined"
The thing is, the second entry in the console listing, above, was created after the Headline value was set by XMPWriteHeadline(). The two values should be different between the two console entries.
If you run the script a second time against the same file, you will see that the Headline value does contain the value that was written in the first run of the script--it just took some time to update the cache, I'm guessing. Here's the second run's log:
Headline value: "Headline Test"
Headline value: "Headline Test"
So, what I'm looking for is a way to insert code (where the comment line "//*** I would like to refresh the cache here ***" appears), to force Bridge CS3 to refresh its cache so that when I call XMPGetHeadline() after calling XMPWriteHeadline(), the Headline value will return the value that was just written.
I hope this is clear enough...
Thanks!!!!
-- Jim
Copy link to clipboard
Copied
Where you have the line
thumb.metadata = new Metadata(updatedPacket);
Try
app.synchronousMode = true;
thumb.metadata = new Metadata(updatedPacket);
app. synchronousMode = false;
By default Bridge's metadata updates happen in the background and not on the main thread, but by using synchronous mode here your script won't continue to the next line until the operation is complete.
-David
Copy link to clipboard
Copied
David,
This is exactly what I was looking for and it works great! Thanks so much!
-- Jim