• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Is there a "wake up" detector?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is there a "wake up" detector?


  • Subject: Is there a "wake up" detector?
  • From: "Marc K. Myers" <email@hidden>
  • Date: Mon, 01 Oct 2001 02:23:20 -0400
  • Organization: [very little]

I have a script with an idle handler that speaks the time to me at a
settable interval (on the hour, on the half hour, on the quarter hour,
etc.) and it works quite well UNLESS I put the machine to sleep.
Apparently the "clock" the system uses to wake up an idled script stops
along with everything else when you sleep the machine. When it wakes up
again the countdown picks up where it left off, but now it's pointed
towards the wrong time.

Is there any sort of Apple Event that gets sent when a machine wakes up
that could be used to trigger a handler in an idled script? And, once
an idle handler has issued a return is there anyway to stop it from
running again after the number of seconds in the return statement? I'd
like to cancel the next execution of the idle handler and reset it to
"go off" at the next exact interval.

When the idle handler is activated I can check to see if the current
date is greater than the set date and if it is reset for the next proper
interval, but this causes the script to miss the first interval after
the waking from sleep. If waking from sleep could trigger something in
the script (and I could cancel the next execution of the run handler)
then I could catch the first exact interval after the machine wakes up.

property theInterval : ""
global nextStart, firstTime

on run
try
if (keys pressed) contains {"Option"} then
set theInterval to ""
end if
end try
repeat until ((class of theInterval is integer) or [optn-L]
(class of theInterval is real))
set dlgRslt to (display dialog "How many times per hour would
you like " & [optn-L]
"the time to be spoken?" default answer "2" buttons {"OK"}
default button 1)
try
set theNbr to (text returned of dlgRslt) as number
if theNbr is not greater than 0 then
set theNbr to 1
else if theNbr > 240 then
set theNbr to 240
end if
set theInterval to round (hours / theNbr)
end try
end repeat
set rightNow to (current date)
set startTime to date "00:00" of rightNow
set nextStart to ((rightNow - startTime) div theInterval) + 1
set nextStart to startTime + (nextStart * theInterval)
set firstTime to true
end run

on idle
if firstTime then
set firstTime to false
else
if (current date) > nextStart then
set rightNow to (current date)
set startTime to date "00:00" of rightNow
set nextStart to ((rightNow - startTime) div theInterval) + 1
set nextStart to startTime + (nextStart * theInterval)
else
set theText to time string of nextStart
set {od, AppleScript's text item delimiters} to [optn-L]
{AppleScript's text item delimiters, {":00"}}
set theText to (text items of theText)
set AppleScript's text item delimiters to od
set theText to (theText as text)
if text -2 thru -1 of theText is "AM" then
set newText to "ay em"
else
set newText to "pee em"
end if
set theText to ((characters 1 thru -3 of theText) & newText)
say "It is now " & theText using "Ralph"
set nextStart to nextStart + theInterval
end if
end if
return (nextStart - (current date))
end idle

NB: "[optn-L]" represents the continuation character

Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[10/1/01 2:12:35 AM]


  • Follow-Ups:
    • Re: Is there a "wake up" detector?
      • From: Sander Tekelenburg <email@hidden>
    • Re: Is there a "wake up" detector?
      • From: Matthew Smith <email@hidden>
    • Re: Is there a "wake up" detector?
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Parsing XML in OS 10.1
  • Next by Date: Re: Printing in QXP [plates missing]
  • Previous by thread: re: Parsing XML in OS 10.1
  • Next by thread: Re: Is there a "wake up" detector?
  • Index(es):
    • Date
    • Thread