Copy link to clipboard
Copied
I currently have a scrippt running in AI that sends a command to PS and it executes. The issue I"m having is that i need PS to complete before AI proceeds.
In my jSX file I have:
  for (var index = 0; index < templateSelected.length; index++) {
      runPScript(templateSelected[index], smartObjTemplate);
  }
This opens photoshop to execute a script:
function runPScript(template, smartObjTemplate) {
var bt = new BridgeTalk;
bt.target = "photoshop";
var script = '\#include \"/Library/Application\ Support/Adobe/CEP/extensions/Yoo_11/jsx/smartObjPrep.jsx\";\n';
script += 'main("' + template + 'separator' + smartObjTemplate + '")';
bt.body = script;
bt.send(10);
return("Completed");
}
The issue I'm having is that Illustrator continues while the PS command runs. That wouldn't be an issue except that this tiem it is. Since I need it to wait so I can execute something else.
I assumed the for loop was synchronous in JSX and would prevent it from running until completed. Any idea how I can accomplish this?
I have been met with inconsistent results of success when trying to debug bridgetalk functions. while testing some things out I wrote a small script to create a QR code in Illustrator by Bridgetalking to Indesign to use the built in QR functions there, and then copy paste it into Illustrator. Overall here are my findings.
Copy link to clipboard
Copied
Hi @OhmsG, is it possible to use the onResult method of the bridge talk message? I learned a bit about it recently at this thread in the Indesign forum. You can see some scripts there that show using it. The main considerations are (a) assign a callback function to the bt.onResult and (b) IMPORTANT: your PS script *must return a value* or the callback won't execute. and (c) the object passed to the callback is another BridgeTalk message and the returned object is the `body` property.
(I'm assuming that BridgeTalk is the same in Illustrator as in Indesign.)
- Mark
Copy link to clipboard
Copied
Thank you, that thread was very helpful. I set the code like this, but unfortuntately I don't get an alert in illustrator. 😞
function runPScript(template, smartObjTemplate) {
    var bt = new BridgeTalk;
    bt.target = "photoshop";
    
    var script = '\#include \"/Library/Application\ Support/Adobe/CEP/extensions/Yoo_11/jsx/smartObjPrep.jsx\";\n';
    script += 'main("' + template + 'separator' + smartObjTemplate + '")\n';
    script += 'return "completed ps";'
    bt.body = script;
    bt.onResult = function(resObj) {
        alert("Illustrator is now running." + resObj.body);
    }
    bt.send(100);
}My expected result was that the alert would appear in illustrator but that is not the case. Any idea what I'm missing?
Copy link to clipboard
Copied
Actually the onReceiveced method mentioned by @RobOctopus did the trick. It alerts.
Copy link to clipboard
Copied
Excellent that you got a solution. Unfortunate that Illustrator doesn't handle BridgeTalk the same as Indesign. 😞
Copy link to clipboard
Copied
I have been met with inconsistent results of success when trying to debug bridgetalk functions. while testing some things out I wrote a small script to create a QR code in Illustrator by Bridgetalking to Indesign to use the built in QR functions there, and then copy paste it into Illustrator. Overall here are my findings.
Someone smarter than me may be able to offer more insight, but i would try a recevied message that PS will do and also an onresult message that will be pushed back to illustrator, which can be a nothing statement and maybe push the timeout to be a little longer. Happy hunting, bridgetalk is a pain.
helpful resource
https://extendscript.docsforadobe.dev/interapplication-communication/bridgetalk-message-object.html
var PromptRes = prompt("Website:","www.Google.com")
    var BT = new BridgeTalk();
    var appspecifier = "indesign";
    if(!BridgeTalk.isRunning(appspecifier)){
        BridgeTalk.launch(appspecifier);
    }
    //var ScriptFileMessage = 'var myDocument = app.documents.add();\rvar QRTangle = myDocument.rectangles.add({geometricBounds:[0.5,0.5,2,2]});\rQRTangle.createHyperlinkQRCode("' + PromptRes + '");\rQRTangle.select();\rapp.copy();\rmyDocument.close(SaveOptions.NO)'
    var ScriptFileMessage = 'var myDocument = app.documents.add();'
    ScriptFileMessage += 'var QRTangle = myDocument.rectangles.add({geometricBounds:[0.5,0.5,2,2]});'
    ScriptFileMessage += 'QRTangle.createHyperlinkQRCode("' + PromptRes + '");'
    ScriptFileMessage += 'QRTangle.select();'
    ScriptFileMessage += 'app.copy();'
    //ScriptFileMessage += '$.sleep(6000);'
    /* testing that it will wait. as long as the function handles before the timeout on the send it should be fine */
    ScriptFileMessage += 'app.activeDocument.close(SaveOptions.NO);'
    BT.target = appspecifier;
    BT.body = ScriptFileMessage;
    /*alert(BT.body)*/
    BT.onResult = function(){
        app.paste();
    }
    BT.onReceived = function(){
        /*forcing the trget application to become frontmost and active. this is the most troublesome part and sometimes likes to work, sometimes it doesnt*/
        var IDActivate = File(BridgeTalk.getAppPath(appspecifier))
        IDActivate.execute();
    }
    BT.send(10);
Copy link to clipboard
Copied
The onReceived method worked! THANK YOU!
Copy link to clipboard
Copied
Thanks @RobOctopus that's great info!
- Mark
 
					
				
				
			
		
 
					
				
				
			
		
Find more inspiration, events, and resources on the new Adobe Community
Explore Now