Skip to content

Instantly share code, notes, and snippets.

@scturtle
Last active July 24, 2020 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scturtle/44ba4f8d9f94afea2c277e816dfd1415 to your computer and use it in GitHub Desktop.
Save scturtle/44ba4f8d9f94afea2c277e816dfd1415 to your computer and use it in GitHub Desktop.
手机插电脑解锁拔下来锁屏
#!/bin/bash -x
VENDOR="05ac:12a8"
SERIAL="XXXXXXXXXXXXXXXXX"
#LOCK="gnome-screensaver-command -l"
#UNLOCK="gnome-screensaver-command -d"
LOCK="slock"
UNLOCK="killall slock"
while true; do
# wait new device status
stdbuf -o0 udevadm monitor --udev | stdbuf -o0 grep usb | head -n1 > /dev/null
sleep 0.1
# check the vendor info
found=$(lsusb -v -d "$VENDOR" | grep iSerial | awk '{print $3}')
# action
if [ "$found" != "$SERIAL" ]; then
echo "plug out"
$LOCK &
else
echo "plug in"
$UNLOCK
fi
sleep 0.1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment