Skip to main content
dulajun
Inspiring
June 25, 2021
Answered

BridgeTalk.getSpecifier doesn't work with Photoshop

  • June 25, 2021
  • 2 replies
  • 628 views
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);
}
This topic has been closed for replies.
Correct answer rob day

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
    }  
};

 

2 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
June 26, 2021

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
    }  
};

 

rob day
Community Expert
Community Expert
June 25, 2021

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"
    }  
};

 

 

dulajun
dulajunAuthor
Inspiring
June 26, 2021

I get:

Error in
Line 7: }

Too many closing braces
rob day
Community Expert
Community Expert
June 26, 2021

Sorry, add a semicolon or return after the last line—I edited the posted code