CHAPTER 5: Interapplication Communication with Scripts Communicating through messages 178
// now you can access the returned array
for (i=0; i< arr.length(); i++)
doSomething(arr[i]);
}
// send the message
bt.send();
Passing an object with toSource and eval
This technique is the only way to pass objects between applications. For example, this
code sends a script that returns an object containing some of the metadata for a
specific file and defines an onResult callback that receives the object.
var bt = new BridgeTalk;
bt.target = "bridge-3.0";
//the script passed to the target application
// returns the object using "toSource"
bt.body = "var tn = new Thumbnail(File(’C:\\Myphotos\\photo1.jpg’));
var md = {fname:tn.core.immediate.name,
fsize:tn.core.immediate.size};
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);
}
// send the message
bt.send();
Passing a DOM object
You can send a script that returns a DOM object, but the resulting object contains only those properties
that were accessed within the script. For example, the following script requests the return of the Adobe
Bridge DOM
Thumbnail object. Only the properties path and uri are accessed by the script, and only
those properties are returned:
var bt = new BridgeTalk;
bt.target = "bridge";
//set up the script passed to the target application
// to return the array using "toSource"
bt.body = "var tn = new Thumbnail(File(’C:\\Myphotos\\photo1.jpg’));
var p = tn.path; var u = tn.uri;
tn.toSource();"
//For the result, use eval to reconstruct the object
bt.onResult = function(resObj) {
// use eval to reconstruct the object
tn = eval(resObj.body);
// now the script can access tn.path and tn.uri,
// but no other properties of the Adobe Bridge DOM Thumbnail object
doSomething (tn.path, tn.uri);
}
// send the message
bt.send();
Comentarios a estos manuales