Scripting question
Thomas Arman
TArman at nc.rr.com
Tue May 9 20:52:13 PDT 2006
James said back in Aug 2004:
Michael doesn't like the idler script ;) He considers it a dangerous
construct. we don't have any plans not to fix it, but it's not at the
top of the list.
Is there a reason that just setting a scheduled event to happen every
minute wouldn't work? I know it logs each run and so will confuse the
log a bit.
There is another way to do it, though it's experimental and not
supported and might change in the future :) But if you're still game
after all that you can play a bit. Michael is going to kick me for
suggesting this to you!
Create a pseudo unit called "Idle Script Control"
in the on script for Idle Script Control add the following.
start idler "Idle Script"
create a global script called "Idle Script" (or whatever you want)
at the end of whatever you need to do every minute add this bit of code
if (status of "Idle Script Control") then
return 60000
else
return 0
end if
This works like the on idle() handler in a stay open applescript. You
return the number of milliseconds you want the script to wait until the
idle handler is called again. So 60000 is 1 minute. You return 0 to
stop the idle handler. So by manually (or in your startup script)
turning on the "Idle Script Control" unit you light this off. It will
continue until you turn off the Idle Script Control unit and that check
falls through to return 0 at the end. There is no "stop idle script"
command, the script itself must return 0 or it will keep running.
This was generally designed for shorter intervals. I use it to capture
series of pictures from my view cameras a second apart for a few
seconds after motion is detected. But it will work for this too. On a
fast machine and a simple script you could get better than 1 second
intervals here that you can't get with scheduled events :)
The setting isn't saved across launches, so you would have to re-turn
the control pseudo on in the startup script or manually after a
restart.
If you were to return a very small number the script would try to run
very very quickly and that could be potentially be very very bad as far
as the performance of the rest of the program is concerned. But each
global script can only be being used in 1 idle timer at a time, so
there is no danger of your starting up multiple copies of it.
So, it's dangerous, undocumented, doesn't log anything by itself,
unsupported and subject to change in the future :) So that makes it
perfect ad much more fun than just a scheduled event right?
Good Luck,
James
More information about the XTensionlist
mailing list