Advertisement
Adrien_Horgnies

autolock

Oct 26th, 2018
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. SESS_PROC=`pgrep gnome-session -n -U $UID`
  4. SESS_PROC_ENV="/proc/$SESS_PROC/environ"
  5. export `xargs -0 -a $SESS_PROC_ENV`
  6.  
  7. # Your phone bluetooth mac address
  8. PHONE_MAC="64:A2:F9:84:AA:54"
  9. # Less means it actives at a smaller distance
  10. SIGNAL_THRESHOLD=15
  11. # Less means it will lock faster (beware it gives you less time to act if there is a problem with this script)
  12. REFRESH_INTERVAL=10
  13.  
  14. INITIAL_CONNECTION=`hcitool rssi $PHONE_MAC 2>&1`
  15.  
  16. while [ "$INITIAL_CONNECTION" = "Not connected." ]
  17. do
  18.     notify-send -u normal "phone never connected, autolock will stay disabled until connected"
  19.  
  20.     sleep 30
  21.     INITIAL_CONNECTION=`hcitool rssi $PHONE_MAC 2>&1`
  22. done
  23.  
  24. notify-send -u normal "phone connected, autolock will start monitoring signal strength"
  25.  
  26. while true
  27. do
  28.     SIGNAL_WEAKNESS=`hcitool rssi $PHONE_MAC | tr -dc '0-9'`
  29.  
  30.     if [ $SIGNAL_WEAKNESS -lt $SIGNAL_THRESHOLD ]; then
  31.         echo "phone is near"
  32.         sleep $REFRESH_INTERVAL
  33.     else
  34.         echo "phone is far"
  35.         gnome-screensaver-command --lock
  36.         # gives 60 seconds to troubleshoot if lock is unwanted
  37.         sleep 60
  38.     fi
  39.  
  40.     echo
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement