Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Add a timeout to bt.send(); I.E. bt.send(8);
Copy link to clipboard
Copied
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");