SyntaxWith timeout of 15 seconds End timeout DescriptionThe 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:
ExamplesThe 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 tell block targeting another application, or it takes an application object as a parameter: try -- catch any timed out errors with timeout of 5 seconds tell application "Finder" get version display dialog "fast" (* let this sit for about 5 secs and raise an error *) end tell end timeout on error -- will be called if 'with timeout' block times out display dialog "Sorry, the operation timed out" end try
|