Article View: adobe.scripting.indesign
Article #188Re: Need help [JS]: select images/captions in InD, switch to Bridge and write to XMP
From: Kasyan_Servetsky
Date: Tue, 31 Mar 2009 15:40
Date: Tue, 31 Mar 2009 15:40
59 lines
2821 bytes
2821 bytes
Great tip, Bob!
If I knew it before, my life would be much easier, when writing inter-application scripts.
I experimented a little and found out that I can even pass parameters. For example:
#target indesign
var someVariable = 'Blah-blah-blah';
function myRemoteFunction(myVariable) {
var Thumbnail = app.document.selections[0];
$.writeln('Thumbnail selected in Bridge -- ' + Thumbnail.name);
$.writeln('myVariable -- ' + myVariable);
}
var bt = new BridgeTalk;
bt.target = 'bridge';
myScript = myRemoteFunction.toString();
myScript += 'myRemoteFunction(\"' + someVariable +'\");\n';
bt.body = myScript
bt.send();
By the way, if I change toString() to toSource() I am unable to pass the variable to Bridge. So I suspect that they are not identical.
But why this script doesn’t work then?
function WriteCaption(myDescription, myPath) {
var thumb = new Thumbnail (File (myPath));
if (thumb.hasMetadata) {
var md = thumb.synchronousMetadata;
var xmp = new XMPMeta(md.serialize());
xmp.deleteProperty(XMPConst.NS_XMP, "Description");
xmp.setProperty(XMPConst.NS_XMP, "Description", myCaption);
var updatedPacket = xmp.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
thumb.metadata = new Metadata(updatedPacket);
}
}
var myDoc = app.activeDocument;
var myCaption = "Blah-blah-bla'";
var myPath = "/d/Test/Del2.tif";
var myDescription = "Image: " + myPath + "; Caption: " + myCaption;
var bt = new BridgeTalk();
bt.target = 'bridge';
var myScript = WriteCaption(myDescription, myPath).toString();
myScript += 'WriteCaption(\"' + myDescription + '\",\"' + myPath + '\");\n';
bt.send();
It says: “Thumbnail does not have a constructor”. So it tries to evaluate the function before applying toString() method and stops. Any suggestions?
I had to resort to the old and proven “myScript += …” approach: Kasyan Servetsky, "Need help [JS]: select images/captions in InD, switch to Bridge and write to XMP" #6, 31 Mar 2009 8:12 am </webx?14@@.59b862e0/5> (post #6)
Kasyan
Technical Details
Message-ID:
<59b86349.6@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newshub.sdsu.edu!webcrossingReferences:
<59b86349.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,68eea3d0b07f2331 X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Kasyan_Servetsky@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.scripting.indesign Subject: Re: Need help [JS]: select images/captions in InD, switch to Bridge and write to XMP Message-ID: <59b86349.6@webcrossing.la2eafNXanI> Date: Tue, 31 Mar 2009 08:40:38 -0700 References: <59b86349.-1@webcrossing.la2eafNXanI> Lines: 46 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit