Re: dd: Delay hogs memory
Re: dd: Delay hogs memory
- Subject: Re: dd: Delay hogs memory
- From: Martin Crisp <email@hidden>
- Date: Thu, 27 Feb 2003 23:00:39 +1100
- Organization: Tesseract Computing
On Thu, 27 Feb 2003 2:53:58 +1100, dave dowling wrote
(in message
<
email@hidden>):
>
Is there a way to have AppleScript execute a delay without eating up so
>
much available RAM? Here's a little alarm clock script I wrote a while
Well, this won't save you any memory, but it might save you some
CPU time.
Use an 'on idle' handler to perform periodic tasks. Use a run
handler to set the initial states (and if that takes a while then
use a property to prevent the idle handler doing anything before
the script is ready).
I hope you don't mind, but I've changed it to be 'settable' at any
time of the day [your script could only be set after midnight].
>
back. I'd like to use AppleScript for other such looping routines with
>
delays, but they use up so much RAM that they're not an option for me.
>
Any ideas? Here's the script I wrote:
[snipped]
-- Should be saved as a 'stay open' application
property doIdle : false
property timeToGetUp : "05:00" -- 5am
property myDelay : 0
property RiseNShine : false
on run
-- we don't want the idle handler to do anything
-- until we're ready
set doIdle to false
set RiseNShine to false
set validTime to false --assume the user will make a mistake :-)
repeat until validTime
try
set tempTimeToGetUp to (text returned of (display dialog
,
"Get up at? [24 hour clock!]" default answer
timeToGetUp))
calc_delay_time(tempTimeToGetUp) returning myDelay
set validTime to true
set timeToGetUp to tempTimeToGetUp
set doIdle to true
on error m number n
beep
beep
set keepGoing to button returned of ,
(display dialog {"Error #", n, " occurred:", return, ,
m, return, return, "Try Again?"} as string)
if keepGoing "OK" then
exit repeat
end if
end try
end repeat
if not validTime then
quit
end if
end run
on calc_delay_time(timeToWake)
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set hrs to (text item 1 of timeToWake) as number
set mins to (text item 2 of timeToWake) as number
set AppleScript's text item delimiters to oldTIDs
set wakeSecs to (hrs * 60 * 60) + (mins * 60)
set daySecs to 24 * 60 * 60
set currentTime to time of (current date)
if currentTime < wakeSecs then
return (wakeSecs - currentTime)
else -- it's between the alarm time and midnight
return (daySecs - (currentTime - wakeSecs))
end if
end calc_delay_time
on idle
if not doIdle then
return 1 -- come back after 1 second
else if not RiseNShine then
set RiseNShine to true -- next time we idle the alarm will go
off
return myDelay -- which will be in myDelay seconds
else
beep
return 3 -- come back after 3 seconds
end if
end idle
Have Fun
Martin
--
I have absolutely no reason to complain about "success" with my
work; [...] And yet, from time to time a boundless sense of
inferiority plagues me, a desperate feeling of general failure; how
does a person acquire such bits of lunacy?
- MC Escher
Almost always SMASHed
_______________________________________________
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.