Also, the body needs to be a Photoshop function as a string. This is the template I use for a more complex function where I’m passing in different types of variables.
#target indesign
#targetengine "session"
var arr = [true, "Hello", 50];
var obj = {h:350, w:500}
//Run a BridgeTalk Photoshop function
runPhotoshop("Hello", arr, 99.99, obj);
/**
* Run function in ID after BT function is completed
* @9397041 the string or object returned from Photoshop
* @Return void
*
*/
function runID(s){
//if the return is an array as a string use split
//alert("Running New ID Fuction—string returned from Photoshop: " + s.split(",")[1])
alert("Running New ID Fuction—string returned from Photoshop: " + s)
}
/**
* Opens Photoshop via Bridgetalk and runs psScript
* @9397041 the string or object sent to Photoshop
* @Return value void
*
*/
function runPhotoshop(s, a, n, o){
//open Photoshop and run psScript
var bt = new BridgeTalk();
bt.target = "photoshop";
//a string representaion of variables and the function to run.
//a string var. Note string single, double quote syntax '"+s+"'
bt.body = "var s = '"+s+"';"
//an array. Note use toSource()
bt.body += "var a = "+a.toSource()+";"
//a number
bt.body += "var n = "+n+";"
//an object. Note use toSource()
bt.body += "var o = "+o.toSource()+";"
//the function and the call
bt.body += psScript.toString() + "psScript();";
$.writeln(bt.body)
bt.onResult = function(resObj) {
runID(resObj.body)
}
bt.onError = function(e) { alert(e.body); };
bt.send(8);
function psScript() {
//make a new string
var ns = s + " World " + a[2] + " " + n + " " + o.h;
//returns the array as a string
//return a
return ns
}
};