Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # locky: lock ALL screens at suspend or hibernate with xscreensaver
- IS_ACTIVE="$( \ps u -C xscreensaver | awk '{print $1}'|grep -v USER )"
- DISPLAYS_TO_CHECK="$( \ps u -C X | tail -n +2 | awk '{print $12}')"
- # check if xscreensaver is running. if not, just skip on.
- if [ -z "$IS_ACTIVE" ]
- then :
- echo "Cannot lock screen. Going to sleep anyway..."
- else
- echo "Locking the screen before sleeping."
- # run the lock command as the user who owns xscreensaver process,
- # and not as root, which won't work.
- # Feed correct display variable for user!
- echo "$IS_ACTIVE"|while read line;
- do
- user="$(getent passwd $line |awk -F : '{print $1}')"
- echo "$DISPLAYS_TO_CHECK"|tr " " "\n"|while read displays;
- do
- if dpyinfo=$(su - $user -c "xdpyinfo -display ${displays}.0 2>&1 1>/dev/null"); then
- echo "$user : DISPLAY=$displays /usr/bin/xscreensaver-command -lock $dpyinfo"
- break;
- su - $user -c "DISPLAY=$displays /usr/bin/xscreensaver-command -lock" &
- else
- echo "$dpyinfo"
- continue;
- fi
- done
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment