Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Created January 20, 2021 07:12
Show Gist options
  • Save maxpoletaev/f0db264286f9d7d1b62c2564bc1023e3 to your computer and use it in GitHub Desktop.
Save maxpoletaev/f0db264286f9d7d1b62c2564bc1023e3 to your computer and use it in GitHub Desktop.
#!/bin/bash
KEY_CODE=55 # Command Key
MAX_IDLE=30
while true; do
idle=`ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'`
echo "Current idle: $idle"
if [[ $idle > $MAX_IDLE ]]; then
osascript -e "tell application \"System Events\" to key code $KEY_CODE"
echo "key pressed"
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment