• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

BridgeTalk.getSpecifier doesn't work with Photoshop

Contributor ,
Jun 25, 2021 Jun 25, 2021

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);
}
TOPICS
Bug , Scripting

Views

358

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 26, 2021 Jun 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 
* @Param the string or object returned from Photoshop 
* @Return void 
* 
*/
function runID(s)
...

Votes

Translate

Translate
Community Expert ,
Jun 25, 2021 Jun 25, 2021

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

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 25, 2021 Jun 25, 2021

Copy link to clipboard

Copied

I get:

Error in
Line 7: }

Too many closing braces

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 26, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 26, 2021

Copy link to clipboard

Copied

LATEST

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines