It is not really clear to me what you’re trying to accomplish. As I understad from your script you want the idle delay to increase by 10 seconds each time a button is pressed. But I understand from your comment that you want to set back your idle delay to something else…
A little clarification might help.
Just a minor comment. You don’t have to set x to missing value if you’re setting it to 10 later in your script:
property x : 10
on clicked theObject
set x to x + 10
end clicked
on idle
return x
end idle
Edit: Idle delay may be a bad choice of words; essentially what I mean is the time between each execution of the on idle script, in your case defined by x.
Ok-- what I meant is, if you are literally idle… Not clicking on something-- then it will count down from 10.
As soon as you click on a button object, then it will reset the countdown back to 10… So therefore you theoretically could click this button constantly, and the idle handler would never do anything because it would always be stuck at 10 (until you stop clicking of course)…
The ‘on idle’ script as you have it now actually increases the idle delay time by 10 seconds every time the button is clicked, instead of resetting it to 10.
Instead of using a button you could measure ‘real’ idle time. In this case any user interaction with the mac (e.g., mouse movement) will reset the script so it doesn’t execute the idle script.
property x : 10
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as number
if idleTime > x then
--do something
say "beep"
end if
return 1
end idle
But maybe if you explain what your end goal is, it would become more clear to me what you want to accomplish with this script.
well… I have an idle handler that simply randomly alters the image view frames in my window sort of as a visual decorative thing (I was heavily impacted by the Beagle Bros idle text decorative effects from the 80s)… This effect is simply nothing more than the program looking impatient like it’s telling the user, “come on… do something”. However, I don’t want this to be happening when the user IS doing something (clicking on a button in the window image view)… So that is my ultimate goal…
More importantly, I want the idle handler to be called if there is mouse activity— just not when the buttons of the window are being clicked…
but even if I do something like this:
property idle_time : 10
on clicked theObject
set idle_time to 10
end on clicked
on idle
display dialog "idle!"
return idle_time
end idle
If I frantically click on my buttons constantly, I still receive a dialog box “idle!” … so this is what I am trying to achieve-- a way to make it so that there will only be an idle if there is no clicking on buttons…
property idle_time : 10
property onClicked : false
on clicked theObject
set onClicked to true
end on clicked
on idle
if onClicked then
set idle_time to 20
else
set idle_time to 10
end if
set onClicked to false
display dialog "idle!"
return idle_time
end idle
I made a simple idle script with a countdown. I wanted it to check for something regularly, but if there was other stuff going on i didn’t want it to check. So certain buttons set the recheck value to 0, and then the idle handler increased the value over time.
on clicked theObject
set recheck to 0
end on clicked
on idle theObject
if recheck is 10 then
do_it()
set recheck to 0
end if
set recheck to recheck + 1
end idle