I want to add a new function to my preflight script which should check color settings chosen in Photoshop. My major problem is that I cant get result outside of bt.onResult function.
Here is where I got so far:

It writes myResult1 variable to console as expected, but myResult2 is undefined. Why?

Another question:
Ive been experimenting with BridgeTalk for some time and found out a strange phenomenon. When I send a BridgeTalk message, lets say, from InDesign to Photoshop in main target engine this script doesnt work, but when in session or a custom one it works. Why so?

I want to explore the possibilities of interapplication communication for a long time. But I cant get reliable information on this topic. Ive read Interapplication Communication with Scripts chapter in JavaScript Tools Guide several times but I couldnt get the example scripts (in Communicating Through Messages section) working.
Ive found a few examples in Adobe Bridge CS3 SDK: SnpSendArray.jsx, SnpSendMessageToInDesign.jsx etc. They work like a charm but their code is hard for me to understand Im not a programmer by background.

So, I have two favors to ask of you:
1st Could someone give me complete and
working examples, similar to given in Communicating Through Messages section?
2nd Could somebody explain to me,
in simple terms , some example from Bridge CS3 SDK?

When you call bt.send() to send your BridgeTalk message, your script doesn't stop. I continues to execute until completion. Your onResult handler function is called when a result is received from the target application.

If you send a BridgeTalk message in such a script, when the result comes back to InDesign, the reference to your script and its scripting engine no longer exists. That's why you MUST use a persistent session in InDesign if you are sending a BridgeTalk message and expecting a response.

In the code you provided, think of the onResult handler as a separate function to be executed at some future time.

Your function infoFromPS() does not return anything, which is why the first writeln returns "undefined".

Your onResult function will execute when a result is received; but, that will be at some future time, long after your infoFromPS() function has already returned.

infofromPS() creates a BT message, sets the properties including the onResult handler, and calls "bt.send()". It then completes, and returns nothing (undefined).

The next line to execute (because infoFromPS() has compelted) is:

$.writeln("myResult2 = " + myResult2);

And since infoFromPS() returned noting, you get

myResult = undefined

in the ESTK.

Then, at some time (depends on how long the script takes to execute in Photoshop - could be hours), a response message is received from Photoshop. At that time, your onResult handler executes:

myResult1 is set to the response message body, the $.writeln writes the correct stuff into the ESTK console, and the onResult function returns myResult1 (which does nothing). You can't "return" something from an onResult handler.

The correct way to use BridgeTalk is to write your script so that it sends the message, and then to write the onResult handler so it does what you need with the returning message.

Thank you so much for the quick reply and intelligible explanation. You opened my eyes to this problem. I reached a deadlock and you showed me the way out of it. I wouldn't be able to solve this thing without your help. Now it works at last!
Thank you again, Bob.

Currently i am working with InDesign CS3. I need to check whether the Object layered images preseneted in my InDesign document, if it is found i need to open the particular image (.ai or .psd) in the (Illustrator or Photoshop) applications and do some layer manipulation in it and do saveAs with different name. Finally i need to relink the image in InDesign.

I have written the script for InDesign, Illustrator & Photoshop seperately for the above stuff. The only thing i need to do is combine these scripts and make them intermediate. Finally i have to run this script from InDesign Scripts palette.

In a script, targetting the different applications is not work out i think so. Hence i tried with Bridge Talk() but facing difficulties on execution from ESTK.