Last active
August 12, 2022 06:49
-
-
Save bitdivine/cb5e8f66683781c141940ba785526d21 to your computer and use it in GitHub Desktop.
Lock Apple Mac screen when bluetooth device, such as a phone, goes out of range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MAC=xx-xx-xx-xx-xx-xx | |
MAX_IDLE=10 | |
while true ; do | |
idle=$(/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/awk '/HIDIdleTime/ {print int($NF/1000000000); exit}') | |
if (( idle < MAX_IDLE )) ; then | |
sleep $(( MAX_IDLE - idle + 1 )) | |
else | |
blueutil --inquiry 4 | grep -E "$MAC" || { | |
echo "Locking screen..." | |
pmset displaysleepnow | |
sleep 2m | |
} | |
sleep 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment