Skip to main content
Rambutan
Inspiring
February 9, 2017
Question

BridgeTalk script woks in all apps except Photoshop

  • February 9, 2017
  • 2 replies
  • 999 views

Hi all, I'm doing some experiments in implementing a generic async function call in Extendscript (read setInterval and setTimeout).

I have have a very rough example working in AI, PPro and AE but the script won't execute correctly in Photoshop.  No errors, just doesn't seem to send the BridgeTalk message to itself.  I know there are better ways to implement the function call etc, just want to get it working in Photoshop for now.

Any ideas?

var testLoop = function(str) {

    for(c = 0; c  < 20; c++)  {

        $.writeln(str + String(c));

        $.sleep(100);

     }

};

var setTimeout = function(fn, fnCall, timeOut) {

    targetApp = BridgeTalk.getSpecifier(BridgeTalk.appName);

    if( targetApp ) {    

        var bt = new BridgeTalk;

        bt.target  = targetApp;

        bt.body = fn.toString() + "; $.sleep(" + timeOut + "); " + fnCall + ";";          

        //bt.onResult = function(returnBtObj) {

            //$.writeln("returnMessage");

        //};   

        bt.send();  

    }

}

$.writeln("MainThreadExecute A");

setTimeout(testLoop, "testLoop('Loop New Thread ')", 3000);

$.writeln("MainThreadExecute B");

TNKS!

G

This topic has been closed for replies.

2 replies

Inspiring
March 24, 2017

Try this:

var testLoop = function(str) {

    for(c = 0; c < 10; c++)  { 

        $.writeln(str + String(c)); 

        $.sleep(100); 

     } 

}; 

 

 

var setTimeout = function(fn, fnString, timeOut) { 

    var targetApp = BridgeTalk.getSpecifier(BridgeTalk.appName);

    if( targetApp ) {      

        var bt = new BridgeTalk; 

        bt.target  = targetApp;  

        bt.body = "var func = " + fn.toSource() + "; $.sleep(" + timeOut + "); func('" + fnString + "');";

        bt.onResult = function(btMessage) {eval(btMessage.body);};

        bt.send();    

    } 

 

 

$.writeln("MainThreadExecute A");

setTimeout(testLoop, "Loop New Thread ", 1000); 

$.writeln("MainThreadExecute B");

SuperMerlin
Inspiring
February 9, 2017

Add a timeout to bt.send(); I.E. bt.send(8);