Q: Help with an applescript
Hello! I am trying to make a script that will log out the guest user after 10 minutes of inactivity. I am having some issues accomplishing this and would appreciate some help. The below script in what I have so far. It works fine to logout the guest user when run in script editor but when exported as an application it will not log out. Instead it quits all applications and will not log out the computer unless you force quit the script application itself. Any help would be much appreciated.
This script below attempts to logout after 10 seconds of inactivity.
repeat
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as number
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as number
if idleTime is greater than or equal to 10 then tell application "System Events"
log out
end tell
delay 1
if idleTime is greater than or equal to 10 then tell application "System Events"
key code 48
end tell
if idleTime is greater than or equal to 10 then tell application "System Events"
key code 49
end tell
delay 10
end repeat
Posted on Sep 19, 2016 12:21 PM