Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- SESS_PROC=`pgrep gnome-session -n -U $UID`
- SESS_PROC_ENV="/proc/$SESS_PROC/environ"
- export `xargs -0 -a $SESS_PROC_ENV`
- # Your phone bluetooth mac address
- PHONE_MAC="64:A2:F9:84:AA:54"
- # Less means it actives at a smaller distance
- SIGNAL_THRESHOLD=15
- # Less means it will lock faster (beware it gives you less time to act if there is a problem with this script)
- REFRESH_INTERVAL=10
- INITIAL_CONNECTION=`hcitool rssi $PHONE_MAC 2>&1`
- while [ "$INITIAL_CONNECTION" = "Not connected." ]
- do
- notify-send -u normal "phone never connected, autolock will stay disabled until connected"
- sleep 30
- INITIAL_CONNECTION=`hcitool rssi $PHONE_MAC 2>&1`
- done
- notify-send -u normal "phone connected, autolock will start monitoring signal strength"
- while true
- do
- SIGNAL_WEAKNESS=`hcitool rssi $PHONE_MAC | tr -dc '0-9'`
- if [ $SIGNAL_WEAKNESS -lt $SIGNAL_THRESHOLD ]; then
- echo "phone is near"
- sleep $REFRESH_INTERVAL
- else
- echo "phone is far"
- gnome-screensaver-command --lock
- # gives 60 seconds to troubleshoot if lock is unwanted
- sleep 60
- fi
- echo
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement