Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kachidk/6d8a3241e5c8ca68a24e885904a03360 to your computer and use it in GitHub Desktop.
Save kachidk/6d8a3241e5c8ca68a24e885904a03360 to your computer and use it in GitHub Desktop.
global computerIsInUse, resetTime
on run
set computerIsInUse to true
set resetTime to (do shell script "date +%s") as integer
end run
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF; exit}'") as integer
if idleTime is greater than 7.4E+10 then
if computerIsInUse then
do shell script "pkill TouchBarServer" user name "YourUserNameGoesThere" password "YourPasswordGoesThere" with administrator privileges
set computerIsInUse to false
end if
end if
if idleTime is less than 7.4E+10 then
set computerIsInUse to true
end if
set now to (do shell script "date +%s") as integer
if (not computerIsInUse) and ((now - resetTime) is greater than 59) then
do shell script "pkill TouchBarServer" user name "YourUserNameGoesThere" password "YourPasswordGoesThere" with administrator privileges
set resetTime to (do shell script "date +%s") as integer
end if
return 1
end idle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment