I’ve been searching for the since yesterday on Idle Handlers and I’m wondering if you can give me some help. What I was assigned to do was make a script for our kisok machines at work. With this script will run whenever the computer goes idle, and it will quit and restart Safari, quit Remote Desktop and delete everything on the desktop. Here is what I have so far…
on Idle
tell application "Safari" -- Quits and Relaunches Safari
quit
delay 5
launch
end tell
tell application "Remote Destkop Connection" -- Quits Remote Desktop
quit
end tell
do shell script "rm -r /Users/kioskuser/Desktop/*" -- Cleans up the Desktop
return 600 -- 10 minutes
end idle
I know its crude, I just started with Applescript a month ago. But thanks in advance for your help.
‘on idle’ is a bit misleading. The script you have posted will run every 10 minutes whether the machine is idle or not. If you want it to run only when something else is true, you’ll have to test for that yourself. You didn’t ask a specific question, so not much more can be said.
I’m sorry I was vague but thank you for your reply.
So how can I make my script do the set commands if the idle handler doesn’t truely check for an idle machine? Can I have it check for the ScreenSaver process even though the screen saver does not run on our Kiosk machines?
Edit: Although they do go to sleep, just no screen saver running.
what i think you are looking for is a process to run either just before “sleep”, or “on wake”. correct me if i’m wrong, but reading your messages makes it seem that when the machine goes to “sleep”, you assume that the previous user is gone and done with the machine (sounds reasonable for a kiosk).
there have been posts about this, but i have not seen a good solution. you may have to artificially generate a condition that tells you that the kiosk has not been used for X amount of time. it would be great if you could do this right before sleep, or just after wake, but i do not know how to do this.
one option you may want to consider as a short term solution would be to run your script just before the kiosks become available to the public. that would be once a day, but until a better solution can be worked out. in this scenario, i’d use power management or pmset to wake the kiosk, run your delete and reset scripts and let it go back to sleep–say 1/2 and our before the kiosks are available. if you are closed to the public at any time during the day, schedule them again.
as i’m thinking of this further i’ve got an idea. not sure how everything would work, but i thought i’d throw it out.
let’s say you set all of the machines to ‘never’ sleep. then you use an AppleScipt that runs all of the time to judge whether the computer is being used or not. after a period of time, it runs your deletes/resets and puts the computer to sleep.
i’m not sure how the AppleScript would test for activity. i may have some time to look into this later.
I use a little app called “Jiggler” to keep my screens awake while I’m working, and leave my displays sleep and disks sleep settings quite short. I never let the CPU sleep. Jiggler works by moving the cursor after a period of inactivity. My point here is that there must be an event somewhere that triggers the screensaver and Jiggler of course - an event that keeps track of cursor movement and keyboard activity, and it isn’t the ScreenSaverEngine which isn’t running when the machine is in use. Does anyone know where and what that is? How does the system keep track of usage?
delay 8
set iT_1 to (do shell script "echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))") as real --> 7.0
set iT_2 to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as real --> 7.0
Either form gives the idle time (the time the machine has been idle since you ran the script). In your ‘on idle’ script, you could run either of them periodically and if the idle time exceeded some number (of seconds) do your thing.
property howLong : 600 -- ten minutes
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as number
if idleTime > howLong then
-- do your maintenance
end if
return howLong
end idle
that’s really neat. i am not familiar with the ioreg command. i couldn’t help but add one component for the OP:
property howLong : 600 -- ten minutes
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as number
if idleTime > howLong then
-- do your maintenance
end if
tell application "System Events"
sleep
end tell
return howLong
end idle