Name
with timeout [of] {integer} second[s] end [timeout]
Syntax
With timeout of 15 seconds End timeout
Description
The with timeout
statement allows you to alter
AppleScript’s default 60-second time limit for the
Apple events that are sent to applications. Normally, if an
application fails to respond to an Apple event within 60 seconds,
AppleScript raises an “Apple event timed
out” error and stops running the script. You can
make this time limit shorter, say 30 seconds, by using the syntax:
with timeout of 30 seconds...end timeout
You enclose the with timeout
structure in a
try
block to trap and report any timeout errors
(see “try”). with timeout
only applies to the following types of commands. In
other words, the with timeout
limit is ignored
unless the command is one of these types:
Commands sent to applications targeted in
tell
blocksScripting addition commands that have application objects as parameters (not too many osaxen have application objects as parameters)
Scripting addition commands that are called inside of
tell
statements that target other applications
Examples
The following example times out if you just let the display
dialog dialog box sit there for over five seconds. This
happens because the display dialog scripting
addition is positioned inside the tell
block
targeting the Finder. Pull the scripting-addition command outside the
tell
block, and the script does not time out.
Again, with timeout
does not work with scripting-addition commands unless the command is part of a ...
Get AppleScript in a Nutshell 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.