Timeout not working

Howdy regulars and new folk alike.

It would seem that timeout is not working on my system as this finishes with a duration of 12.98s

set x to 0
with timeout of 1 second
	repeat with i from 1 to 10000000
		set x to x + 1
	end repeat
end timeout

Any thoughts? I came upon this while trying to test a structure like this.

	with timeout of x seconds
		-- meat & potatoes
	end timeout
on error errMsg number errNUm
	-- was hoping to catch any errors or the time out here for
	-- log writing purposes
end try

Any way to do this?

Hello James. I believe timeout only affects individual statements. Sadly, I don’t see any way for you to achieve the desired effect.

Thanks Bruce… actually timeout itself is annoying me even with single statements.

with timeout of 1 second
	mount volume "<protocol>://<user>:<pass>@<ip>/<share>"
end timeout

I run that and about 5 seconds (over worked server) my share mounts… yet it never times out :frowning:

Hi James,

‘with timeout’ is not used to make statements time out. It’s used to make the script not time out. Do you knnow what I mean?


totally got ya kel I often use fuzzy logic regardless of th language I’m in… it’s a bad habit. So for the sake of my being annoying can you think of a good way to time the script out?

Here’s an example using dialogs in an app:

tell application "Safari"
	with timeout of 3 * minutes seconds
		display dialog (current date) as string
	end timeout
end tell

When you display dialogs in an app, it times out in about two seconds. The timeout statement gives it an extra minute before timeout. That’s why they usually give it a huge number for the seconds, so it never times out.


I already answered James’ question as it was posted on the AppleScript users list a few days ago, but there’s a need to clear this up here in this thread as question is still dangling.

First, timeout does not work only on single statements. You can stick as many statements as you want between the beginning and ending timeout statements. Whether or not the timeout works depends on “who” those statements belong to.

Second, timeout only applies to Apple Events sent to applications. If you have a Plain Vanilla AppleScript statement in a timeout it will not time out. The timeout is used because AppleScript is waiting for the application response and will eventually need to give up if there is no response forthcoming. Applescript doesn’t have to wait for itself to respond if it didn’t send any external Apple Event.

The example given above ONLY works because the dialog is called in the Safari tell block. Take that away (you don’t need Safari to get a dialog or the date) and the timeout doesn’t function. So wrapping the timeout in an application tell block that encloses statements that have nothing to do with the application can render the timeout functional. Take that Safari tell block away and the code still runs, but the timeout will not be invoked.

So far as I know - and that’s not very far - there is no way - apart from the wrapping in an application tell block - to get a timeout on a plain vanilla applescript statement.

  • web

Have you played with it enough to know whether it would work with a background application tell block (so as not to run anything visible)?

Hi web,

it’s right, that all lines within a timeout block are affected to control the timeout error but
the given time will be resetted for every single command which sends Apple Events

Hi Adam,

That’s what I was thinking. If you could connect what James wants to do with some app as in my example, then you could wait for a reply.


Throws an error if you try it with System Events.

Darn, I don’t have any volumes to play with. :frowning:

Sheesh - how do you back up? Can’t you try to get the entire contents of a CD or something like that?

Grüezi Stefan,

Yes, the timeout is invoked on every command for which an event is sent.

I’m not sure about the background application, but if the command inside of the tell block is a Plain Vanilla AppleScript command then even a visible application shouldn’t “do” anything. If I calculate the sum of two numbers in a Finder tell block the Finder doesn’t actually do anything at all. If all one needs is a wrapper for the command, then it shouldn’t be an issue. But I didn’t test this in any way.


  • web

Hi Adam,

That’s an idea. I backup on cd, but didn’t know you could mount and unmount without ejecting the disk. I’ll se if that’s possible.


Has anyone else noticed that the “With timeout of x seconds” in Leopard now defaults to 3 minutes for dialog boxes???

I use applescripts to get things done during the day and used the dialog boxes as reminders of what I was working on. In Tiger this worked great because I could have the dialog boxes stay up for hours at a time, come back to my computer, and it would still be there.

Now in the official release of Leopard 10.5, it doesn’t matter how many seconds I put above 180, it always quits at 3 minutes. Can anybody explain this to me? or help me? I’ve searched the literature at Apple’s developer documentation and I can’t find anything related to timeout changes.

with timeout of 1000 seconds
display dialog "Sample text for dialog box"
end timeout

I think it is compiling as "display dialog “Sample text for dialog box” giving up after 1000 seconds (even though it is written as above). and the ‘giving up after’, even in 10.4, seemed to be limited to 3 minutes. Does anybody else know what’s going on with timeout limits in Leopard 10.5?

Model: MacBook
AppleScript: 2.0
Browser: Safari 523.10
Operating System: Mac OS X (10.5)

It’s actually 5 minutes. But still. this is a problem if you need a dialog box to stay up longer than this amount of time. It worked fine in Tiger.