Skip to content

Instantly share code, notes, and snippets.

@petrjahoda
Last active April 7, 2024 15:22
Show Gist options
  • Save petrjahoda/f9975cae7d0be03c2fbbc3b4943966b4 to your computer and use it in GitHub Desktop.
Save petrjahoda/f9975cae7d0be03c2fbbc3b4943966b4 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
@Adri1dolent
Copy link

Thanks for the great work :) 💯

@maikelrichard
Copy link

maikelrichard commented Jan 9, 2024

on idle
	do shell script "pkill TouchBarServer" user name "USERNAME" password "PASSWORD" with administrator privileges
	delay 3
end idle

for idle wait 30 seconds before reset, for me fix this method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment