Re: Delay hogs memory
Re: Delay hogs memory
- Subject: Re: Delay hogs memory
- From: Mr Tea <email@hidden>
- Date: Thu, 27 Feb 2003 11:15:59 +0000
This from dave dowling - dated 27/2/03 7:53 am:
>
Is there a way to have AppleScript execute a delay without eating up so
>
much available RAM?
Why yes, Dave. I believe there is. What you want is an idle handler.
global theCountdown
set theCountdown to 3
tell application "Finder" to activate
on idle
if theCountdown > 0 then
repeat theCountdown times
beep
delay 1
end repeat
set theCountdown to theCountdown - 1
else
activate
display dialog "Going to quit now" buttons {"OK"} default button 1
giving up after 3
quit
end if
return 5 -- number of seconds before idle handler runs again
end idle
on quit
continue quit
end quit
(Tested in OS X 10.2.4)
A script containing an idle handler needs to be saved as an application with
the 'stay-open' option checked. Without the 'quit' message and handler, the
applet will just keep ticking over until you quit it yourself. When no
'return' value is specified, the idle period defaults to 30 seconds (IIRC).
PERSONAL STUPIDITY NOTE: For an embarrassingly long time, I laboured under
the misapprehension that an idle handler was something that waited for the
system to be idle before running. That sounded sensible, and seemed to be
what was implied by the syntax 'on idle, do stuff...'. I thought that this
was a way to have things like backups run when nothing else was going on. Of
course, when I started trying to use idle handlers in my own scripts, I came
to realise how idiotic and delusional this notion was.
If I was asked to explain the idle thing now, I suppose I might use the
analogy of a bicycle on a flat road. Instead of pushing the pedals all the
time, a script containing an idle handler only pumps them when the code in
the handler is running - the rest of the time it sticks its legs out to the
sides and simply freewheels along, using minimal effort and resources. (Just
don't ask how gravity and friction fit into this analogy.)
Cordially,
Nick
(pp Mr Tea)
--
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.