don´t get "with timeout"

hi,

i don´t get what timeout really does. let´s say, copying of the file takes 59 seconds at most:


with timeout of 60 seconds
	copy x to y
end timeout

what exactly happens.

is 60 seconds = 60 seconds (sounds stupid, but i wonder).
does the script wait for 60 seconds or does the timeout end, if the copying takes 10 seconds only?

Hi,

in your code syntax the timeout block is useless.
It affects only Apple Events sent to applications.
The timeout block just watches the response of an Apple Event

i don´t really understand “Apple Event”. i found this in
http://dougscripts.com/itunes/


tell application "iTunes"
	if selection is not {} then
		set sel to selection
		with timeout of 300000 seconds
			repeat with aTrack in sel
				repeat with anArtwork in artworks of aTrack
					if downloaded of anArtwork is true then
						set theData to data of anArtwork
						set data of anArtwork to theData
					end if
				end repeat
			end repeat
		end timeout
	else
		display dialog "Select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
	end if
end tell

it takes very long. that´s the background of my question.


set theData to data of anArtwork

is an Apple Event sent to iTunes to retrieve the data

copy x to y

is no Apple Event

I mostly use it on display dialogs. By default, if the user leaves the dialog up for a bit without responding, the script will timeout. To prevent that you can wrap your display dialog line in a timeout of an hour or a couple of hours to keep the program from crashing.

Basically you would typically use it to override the default timeout (which essentially errors out your script) if something is taking a while.

Edit: In the dougscript above, the timeout is preventing the repeat loop from timing out if there are so many songs in the library that it would take a long time to repeat through them all.

i see. so the timeout does not slow down the script at all and 300000 seconds is just any very long value.

thanx. very helpful.

It’s more comfortable to use the giving up after parameter of display dialog :wink:

Not at all. The timeout block just changes the default timeout value of 120 secs up to ~ 83 hrs, nothing else

Actually I use both a timeout and a giving up after. Got tired of timeout errors. Should the giving up after alone prevent the timeout error? I guess I never tried just that…

Airbuff, think of the timeout loop not as “make this last for 300000 seconds” but more as “it’s OK if this lasts for up to 300000 seconds so don’t throw an error”.

got it. thanx.