Created
June 15, 2019 10:34
-
-
Save grimpy/926f8dad863caea349ff11fae4cad77a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
BTHW="A0:9E:1A:14:FE:10" # Enter your Phone Bluetooth hardware address | |
TIMEOUT=30000 | |
function expired() { | |
inactivetime=$(xprintidle) | |
echo $inactivetime | |
if [ "$inactivetime" -lt "$TIMEOUT" ]; then | |
return 1 | |
fi | |
return 0 | |
} | |
while true | |
do # Run only if screen is locked | |
if ! expired; then | |
sleep $((($TIMEOUT - $inactivetime + 1000) / 1000)) | |
continue | |
fi | |
if ! bluetoothctl info $BTHW | grep "Connected: yes" >/dev/null 2>/dev/null; then | |
if bluetoothctl connect $BTHW ; then | |
continue | |
fi | |
notify-send "Locking in 5" | |
sleep 5 | |
if expired; then | |
xlock & | |
wait | |
fi | |
fi | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment