I had a requirement to lock my laptop at work automatically without having to touch it. The way devised by a friend was to enable the screensaver and its locking mechanism every time my phone’s bluetooth was out of range i.e. could not be seen via
hcitool scan. It works *really well*! Now my laptop locks whenever I leave the room.
Update: It seems this was popular with reddit.com/r/linux, so I’ve uploaded the script to github and added unlocking support!
Here’s the code:
DEVICE=the bluetooth MAC id
DEV_NAME="The actual device's alias/name"
INTERVAL=5 # in seconds
# Start xscreensaver if it's not already running
if [ $? -eq 1 ]; then
echo "Starting xscreensaver..."
# Assumes you've already paired and trusted the device
while [ 1 ]; do
opt=`hcitool name $DEVICE`
if [ "$opt" = "$DEV_NAME" ]; then
echo "Device found. Not locking"
echo "Can't find device $DEVICE ($DEV_NAME); locking!"