Last active
December 1, 2017 00:53
-
-
Save ivan/8235046d6a27b6a338c3fa34d25108e5 to your computer and use it in GitHub Desktop.
xscreensaver-wait-for-unlock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run this script under `setsid -w` to avoid killing parent processes | |
# e.g. your lock script and xfsettingsd | |
set -u | |
# Kill `xscreensaver-command -watch` when we exit | |
# https://stackoverflow.com/a/22644006/738390 | |
trap "exit" INT TERM | |
trap "kill 0" EXIT | |
# Protect against potential xscreensaver-command -watch crashes | |
while true; do | |
# https://unix.stackexchange.com/questions/166546/bash-cannot-break-out-of-piped-while-read-loop-process-substitution-works | |
while read line; do | |
if echo -E "$line" | grep -q "^UNBLANK "; then | |
# Make sure the screen is actually unlocked | |
xscreensaver-command -time | grep -q " screen non-blanked since " && exit 0 || echo "saw UNBLANK but screen was not unlocked" | |
fi | |
done < <(xscreensaver-command -watch) | |
echo "crashed, restarting: xscreensaver-command -watch" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Without the
kill 0
: https://gist.github.com/ivan/2453278021229bc5ff71c01c727e0da7