How to pass callback so AI will wait for PS to complete
Hi all! I've tried everything I can think of but unfortunately with no promises or awaits I'm kind of stuck.
My goal is to wait for PS to finish executing before AI continues. Here goes:
This portion of my script calls a method "runPScript" which executes in PS.
I'd like to wait for it to complete before AI takes off again. Alert runs immediately after PS launches.
for (var index = 0; index < templateSelected.length; index++) {
runPScript(templateSelected[index], smartObjTemplate, false);
}
alert('ran 5958')
I removed somet things to condense it, here is runPScript
function runPScript(template, smartObjTemplate, last) {
var bt = new BridgeTalk;
bt.target = "photoshop";
...
if(last) {
bt.onResult = function(resObj) {
alert("Illustrator is now running." + resObj.body);
}
bt.onReceived = function() {
return('completed');
}
}
bt.send(100);
}
I added the onReceived assuming that the script would wait for this command but obviously I'm wrong. Any idea how I can accomplish this?
