
CHAPTER 5: Interapplication Communication with Scripts Communicating through messages 174
A response message can be:
X The result of an error in processing the message. This is handled by the onError callback.
If an error occurs in processing the message
body (as the result of a JavaScript syntax error, for
instance), the target application invokes the
onError callback, passing a response message that
contains the error code and error message. If you do not have an
onError callback defined, the error is
completely transparent. It can appear that the message has not been processed, since no result is ever
returned to the
onResult callback.
X A notification of receipt of the message. This is handled by the onReceived callback.
Message sending is asynchronous. Getting a true result from the send method does not guarantee
that your message was actually received by the target application. If you want to be notified of the
receipt of your message, define the onReceived
callback in the message object. The target sends back
the original message object to this callback, first replacing the
body value with an empty string.
X The result of a time-out. This is handled by the onTimeout callback.
You can specify a number of seconds in a message object’s timeout
property. If the message is not
removed from the input queue for processing before the time elapses, it is discarded. If the sender has
defined an onTimeout
callback for the message, the target application sends a time-out message back
to the sender.
X Intermediate responses. These are handled by the onResult callback.
The script that you send can send back intermediate responses by invoking the original message
object’s sendResult()
method. It can send data of any type, but that data is packaged into a body string
in a new message object, which is passed to your callback. See “
Passing values between applications”
on page 176.
X The final result of processing the message. This is handled by the onResult callback.
When it finishes processing your message, the target application can send back a result of any type. If
you have sent a script, and the target application is using the default
BridgeTalk.onReceive callback
to process messages, the return value is the final result of evaluating that script. In any case, the return
value is packaged into a
body string in a new message object, which is passed to your callback. See
“
Passing values between applications” on page 176.
The following examples demonstrate how to handle simple responses and multiple responses, and how to
integrate error handling with response handling.
Example: Receiving a simple response
In this example, an application script asks Adobe Bridge to find out how many files and folders are in a
certain folder, which the evaluation of the script returns. (The default
BridgeTalk.onReceive method
processes this correctly.)
The
onResult method saves that number in fileCountResult, a script-defined property of the message,
for later use.
var bt = new BridgeTalk;
bt.target = "bridge-3.0";
bt.body = "new Document(’C:\\BridgeScripts’);
app.document.target.children.length;"
bt.onResult = function( retObj ) {
processFileCount(retObj.body);
}
Kommentare zu diesen Handbüchern