With
A with block is used to modify Apple events sent within its code to target applications, specifying certain external attributes of those Apple events. Two types of with block are currently defined: a timeout block and a transaction block.
Timeout
Recall from Section 4.1 that during interapplication communications, the sender of an Apple event may attach to that Apple event a specification of how long it is willing to wait for a reply. This is the Apple event’s timeout period. If the target does not reply within the specified timeout period, for whatever reason (the operation might be too lengthy, the target application might be otherwise engaged, and so forth), the System stops waiting for a reply and reports to the sender that the Apple event timed out. This report arrives as an error; your script can handle this error and proceed (see Section 12.7, later in this chapter).
This entire mechanism is valuable because, among other things, it saves the sender from hanging indefinitely while waiting for the target to reply; if the target takes too long to reply, the sender is able to proceed nonetheless. Of course, the sender must then do without any reply from the target; but the point is that a script can be written to take account of a problem of this kind, and reporting the problem to the user and proceeding or terminating in good order is certainly preferable to hanging or appearing to hang while waiting for a reply that is taking a long time to arrive and that may, indeed, ...
Get AppleScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.