How do I lock/unlock my screen using my iPhone and USB dock?
Found an excellent script here courtesy of Evan Boldt on how to do this. Thanks Evan!
First find out the id of your device by using lsusb
The create a script under your home dir (let's use /home/me/iPhoneLock.sh for this example) that looks sort of like this:
#!/bin/bash
#Replace with the ID of your USB device
id="ID ffff:1234 Apple, Inc. iPhone 3G"
serial="12345"
#runs every 2 seconds
for ((i=0; i<=30; i++))
do
if [ -z "`lsusb -v 2> /dev/null | grep "$serial"`" ]
then
echo "Device is NOT plugged in"
if [ -n "`DISPLAY=:0 gnome-screensaver-command --query | grep "is active"`" ]
then
if [ -e /tmp/autoUnlock.lock ]
then
#stop locking the screen
rm /tmp/autoUnlock.lock
fi
elif [ -e /tmp/autoUnlock.lock ]
then
DISPLAY=:0 notify-send -t 5000 --icon=dialog-info "iPhone Disconnected" "Locking screen"
#lock the desktop
DISPLAY=:0 gnome-screensaver-command --lock
rm /tmp/autoUnlock.lock
fi
else
echo "iPhone IS plugged in"
if [ ! -e /tmp/autoUnlock.lock ]
then
DISPLAY=:0 gnome-screensaver-command --deactivate
DISPLAY=:0 notify-send -t 5000 --icon=dialog-info "iPhone Connected" "Welcome Back!"
touch /tmp/autoUnlock.lock
fi
fi
sleep 2
done
Next, edit your crontab:
crontab -e
Finally configure it so that it runs every minute:
* * * * * bash /home/username/bin/autoUnlock & >/dev/null 2>&1
Note of warning though: Of course this means that anyone with your phone will be able to unlock your screen. A nice improvement would be to only unlock your screen if your phone was unlocked.
This of course is applicable to any usb device.
The script is licensed under the CC-GNU GPL version 2.0 or later.