Returning values from BridgeTalk

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

amandak695

Returning values from BridgeTalk

Post by amandak695 »

xbytor wrote:In the Bridge docs, there's a section called 'Passing values between applications' on page 190 that describes how to do it.

The code you'd probably be interested in is this:
Code: Select allvar bt = new BridgeTalk;
bt.target = "bridge";

//the script passed to the target application returns the object using "toSource"
bt.body = "var tn = new Thumbnail(File('C:\\Myphotos\\photo1.jpg'));\r" +
   "var md = {fname:tn.metadata.FileName,  fsize:tn.metadata.FileSize};\r" +
   "md.toSource();"

//For the result, use eval to reconstruct the object
bt.onResult = function(resObj) {
   md = bt.result = eval(resObj.body);

   // Now you can access fname and fsize properties
   doSomething (md.fname, md.fsize);
};

//launch the Bridge if it's not already running
if (!BridgeTalk.isRunning("bridge")) {
   BridgeTalk.launch("bridge");
}

// send the message
bt.send();

The key here is defining the onResult method in the BridgeTalk object. When the expression has been eval'd on the other side, the result of that expression is sent back as the parameter to the onResult method. Note that this happens asynchronously. I'm not sure if there is a way of forcing this to work synchronously.

-X
Well, great work! You have helped me to improve my knowledge about this field. Thank you so much for sharing.