Re: idle handlers and computer sleep
Re: idle handlers and computer sleep
- Subject: Re: idle handlers and computer sleep
- From: Donald Hall <email@hidden>
- Date: Tue, 21 Oct 2003 22:34:07 -0600
Last week I posed the following question on the list:
>
Does anyone know what happens to a stay open script application that
>
has an idle handler when the computer goes to sleep?
>
>
Is the amount of time remaining before the idle handler is to run
>
again remembered? (For example, the idle handler has a return of 30
>
seconds, and the computer goes to sleep 10 seconds into this time.
>
On awakening, does the system wait 20 seconds to run idle again, or
>
some other time (such as 30 or 0)?
As no one replied, I did some experimenting to see what happened. I
could think of two ways the return from the idle handler might work:
using the returned number of seconds to calculate a time on the
system clock for the idle handler to restart, or starting some sort
of countdown timer that triggered the idle handler to run when it
expired. It appears to me that the latter method (or something
similar) is used.
I used the following stay open script application to do the testing
(OS X 10.2.2):
property deltaT : 30
global expectedReturnTime
global fref
global reps
property theFile : ""
on run
set expectedReturnTime to (current date) + 2 * deltaT --
intialize value, deltaT is arbitrary, idle starts1st time right after
run
if theFile = "" then
set theFolder to (choose folder) as text
set theFile to theFolder & "waketest.txt"
end if
set fref to open for access file theFile with write permission
set reps to 1
end run
on idle
beep
set e to time string of expectedReturnTime
set n to time string of (current date)
set d to return & (reps as text) & ". " & e & ", " & n
write d to fref starting at eof
if expectedReturnTime < (current date) then
set d to " time exceeded by " & ((current date) -
expectedReturnTime + 2) & " seconds" & return
write d to fref starting at eof
end if
set expectedReturnTime to (current date) + deltaT + 2 -- add
a bit of margin for loop overhead, etc
set reps to reps + 1
return deltaT
end idle
on quit
write return to fref starting at eof
close access fref
continue quit
end quit
I started the application and let it run for a few cycles, then put
the computer to sleep for more than 30 seconds. I then woke up the
system, let the program run for at least one more cycle, and then
quit the program and examined the waketest.txt file. I used my wrist
watch to time the sleep. My wrist watch and the computer clock
appeared to read within 1 second of each other.
Here are the results:
Trial 1
Start of last run of idle handler before sleep: 11:21:02
Start of sleep: 11:21:05
Hit any key to wake: 11:22:06
Start of first run of idle handler after sleep: 11:22:29
Time left in idle period at start of sleep: 27 seconds
Time from wake initiation to first run of idle handler: 23 seconds
Trial 2
Start of last run of idle handler before sleep: 11:56:36
Start of sleep: 11:56:48
Hit any key to wake: 11:59:03
Start of first run of idle handler after sleep: 11:59:19
Time left in idle period at start of sleep: 18 seconds
Time from wake initiation to first run of idle handler: 16 seconds
Trial 3
Start of last run of idle handler before sleep: 2:15:02
Start of sleep: 2:15:09
Hit any key to wake: 2:16:47
Start of first run of idle handler after sleep: 2:17:08
Time left in idle period at start of sleep: 23 seconds
Time from wake initiation to first run of idle handler: 21 seconds
It looks like the time left in the idle period and the time it takes
for the idle handler to restart are closely correlated. The
differences in the two times (e.g. 18 and 16 seconds) are probably a
mixture of sleep overhead, the small differences between my watch and
the system clock, and experimental error.
It sure would be nice if we had the pmgtwake event as we did in OS 9!
Don
--
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
email@hidden
http://www.appsandmore.com
_______________________________________________
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.