Skip to content

Instantly share code, notes, and snippets.

@rchernobelskiy
Last active September 6, 2023 09:01
Show Gist options
  • Save rchernobelskiy/5986a3bc334bd2107ff7e34af254053a to your computer and use it in GitHub Desktop.
Save rchernobelskiy/5986a3bc334bd2107ff7e34af254053a to your computer and use it in GitHub Desktop.
Discourage use of mac during off hours by putting it to sleep automatically once a minute if it's awake
#!/bin/bash
if test $(date '+%H') -ge 22 || test $(date '+%H') -le 5; then
if expr $(date '+%M') % 2 && /usr/local/bin/brightness -l|grep -q 'active, awake, online'; then
cvol=$(osascript -e 'output volume of (get volume settings)')
#curb=$(brightness -l|tail -1|cut -d' ' -f4)
finishat=$(expr $(date '+%s') + 60)
while test $(date '+%s') -lt $finishat; do
#brightness 0
osascript -e "set volume output volume 0"
pmset displaysleepnow
sleep 0.3
done
osascript -e "set volume output volume $cvol"
#brightness $curb
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment