Script executing itself?
James Sentman
james at sentman.com
Sun Mar 13 10:30:41 EDT 2016
If it’s just the timing of the script running that you want to be able to change there are several ways to do that without resorting to the execute script. I might do something with the start idle verb like this:
in a global script put the code you want to be able to change the timing of into a handler and add the code to start the idler to the main portion of the script along with a property in which to store the seconds for the delay.
property delaySeconds:5
start idler handler “doMyWork” in (delaySeconds * 1000) — idlers take milliseconds so to get seconds multiply by 1000!
on doMyWork()
write log “I am doing work with an interval of “ & delaySeconds & “ seconds!"
return (delaySeconds * 1000) —return the number of milliseconds to wait till the next execution
end doMyWork
in this case the doMyWork will run every 5 seconds. To change it just change the value of that property from any other script like:
set delaySeconds in xGlobalScript “the name of that global script” to 20
set the delay to 0 in order to stop the idler running.
now you have control of the timing of that script handler running. You can also set any other local variables in the script that way too. If you would want to pass more parameters to the handler just make more properties and set them up with more set statements whenever they need to change.
Does this do what you’re describing? I can’t quite wrap my head around what else you might be doing. If this isn’t it then send more detailed example of what you’re doing so I can understand.
> On Mar 12, 2016, at 9:48 PM, Rob Lewis <rob at whidbey.com> wrote:
>
> The basic issue I’m trying to address is: how do you make a script that runs every N seconds, where N is a parameter that another script can set and change?
>
Thanks,
James
James Sentman http://www.PlanetaryGear.org http://MacHomeAutomation.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.machomeautomation.com/pipermail/xtensionlist/attachments/20160313/843a5729/attachment.html>
More information about the XTensionList
mailing list