Re: Best way to wait
Re: Best way to wait
- Subject: Re: Best way to wait
- From: "Marc K. Myers" <email@hidden>
- Date: Thu, 30 Nov 2000 17:41:24 -0500
- Organization: [very little]
Pier Kuipers wrote:
>
Date: Thu, 30 Nov 2000 12:19:38 +0000
>
To: Applescript Mailing List <email@hidden>
>
From: Pier Kuipers <email@hidden>
>
Subject: Re: Best way to wait
>
>
How about this one:
>
>
display dialog "Hello!"
>
set x to ((current date) + 25)
>
repeat
>
if (current date) > x then exit repeat
>
end repeat
>
activate me
>
beep 3
>
display dialog "Hello Again!"
>
>
Save as application, launch, and see what happens: the script keeps
>
running for 25 seconds, during which time you could be doing other
>
things.
>
>
Pier.
That's actually about the worst way to wait! It ties up your computer by
constantly retrieving the current date and doing comparisons. Makes it
difficult for any other application to get any cycles. The AppleScript
Sourcebook has a whole section on this at
<
http://www.AppleScriptSourcebook.com/tips/idlethoughts.html>. A much
more efficient way would be to use an idle handler like this:
global firstTime
on run
set firstTime to true
end run
on idle
if firstTime
set firstTime to false
return 25
end if
[do the stuff you want to do after 25 seconds]
end idle
If you wanted to check for some event every 25 seconds and do something
when it occurs and then quit, the idle handler would look like this:
on idle
if myEvent then
[do the stuff you want to do if the event has happened]
quit
end if
return 25
end idle
Marc [11/30/00 4:41:44 PM]