Skip to content

Instantly share code, notes, and snippets.

@gehaxelt
Created January 13, 2018 22:41
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 gehaxelt/949a130b5e244d8aa987873c0cac5aaa to your computer and use it in GitHub Desktop.
Save gehaxelt/949a130b5e244d8aa987873c0cac5aaa to your computer and use it in GitHub Desktop.
Automatically lock all screens with xscreensaver-command --lock
#!/bin/sh
# Based on https://raw.githubusercontent.com/aminb/usb-lock/master/onusbunplug.sh
getXuser() {
user=`pinky| grep -m1 ":$displaynum" | awk '{print $1}'`
if [ x"$user" != x"" ]; then
userhome=`getent passwd $user | cut -d: -f6`
export XAUTHORITY="$userhome/.Xauthority"
else
export XAUTHORITY=""
fi
}
for x in /tmp/.X11-unix/*; do
displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
getXuser
if [ x"$XAUTHORITY" != x"" ]; then
# extract current state
export DISPLAY=":$displaynum"
fi
done
su "$user" -c "/usr/bin/xscreensaver-command --lock"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment