Passing a variable from Photoshop to Illustrator
Alright, so I've been on here a lot the last couple weeks trying to figure out BridgeTalk, and I am starting to get the hang of it. I am writing an Illustrator script which will open a specified template and then grab Photoshop's active document and place it on the template. I have everything working perfectly with one hiccup. The script goes to Photoshop, grabs the filepath, opens the Illustrator doc, and places the file perfectly. BUT it always takes two runs through the script for it to work. It's the weirdest thing. So if I run the script when PS first opens, it gives me an error; if I run it again it works perfectly, but if I close that PS doc and open a new one, then run the script, it places the previous document!
I am stumped and have tried everything I can think of. Here is a simplified version of the part of the script that produces the error. The first time I run the script, "alert(psFile)" is completely wrong, but when I run it again it works perfectly.
#target illustrator
var psFile;
infoFromPS ();
var illTemp = File("/Users/art1/Desktop/template.ai");
app.open(illTemp);
var doc = app.activeDocument;
function infoFromPS() {
var bt = new BridgeTalk;
bt.target = "photoshop";
bt.body = "app.activeDocument.fullName;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
psFile = File(myResult);
}
bt.send();
}
alert(psFile);
