Copy link to clipboard
Copied
var targetPhotoshop = BridgeTalk.getSpecifier ("photoshop");
/*test*/alert ("targetPhotoshop.appStatus\n" + targetPhotoshop.appStatus);
var talkPhotoshop = new BridgeTalk;
talkPhotoshop.target = targetPhotoshop;
talkPhotoshop.onResult = function (returnBtObj) { checkDocLen (returnBtObj.body); }
talkPhotoshop.body = "return app.documents.length;";
talkPhotoshop.send ();
function checkDocLen (theBody) {
alert ("Open Documents count\n" + theBody);
}
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
* @Param the string or object returned from Photoshop
* @Return void
*
*/
function runID(s)
...
Copy link to clipboard
Copied
Try this:
runPhotoshop();
/**
* Opens Photoshop via Bridgetalk and runs psScript
* value void
*
*/
function runPhotoshop(){
//open Photoshop and run psScript
var bt = new BridgeTalk();
bt.target = BridgeTalk.getSpecifier("photoshop");
bt.body = "var func = " + psScript.toString() + "func();";
bt.onResult = function(resObj) {
alert(resObj.body);
}
bt.onError = function( inBT ) { alert(inBT.body); };
bt.send(8);
function psScript() {
var docs = app.documents.length;
alert("Photoshop is running. Open Documents count: " + docs)
return "Message from Photoshop to InDesign: Hello"
}
};
Copy link to clipboard
Copied
I get:
Error in
Line 7: }
Too many closing braces
Copy link to clipboard
Copied
Sorry, add a semicolon or return after the last line—I edited the posted code
Copy link to clipboard
Copied
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
* @Param 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
* @Param 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
}
};