Skip to content

Instantly share code, notes, and snippets.

@grimpy
Created June 15, 2019 10:34
Show Gist options
  • Save grimpy/926f8dad863caea349ff11fae4cad77a to your computer and use it in GitHub Desktop.
Save grimpy/926f8dad863caea349ff11fae4cad77a to your computer and use it in GitHub Desktop.
#!/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