Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active December 1, 2017 00:53
Show Gist options
  • Save ivan/8235046d6a27b6a338c3fa34d25108e5 to your computer and use it in GitHub Desktop.
Save ivan/8235046d6a27b6a338c3fa34d25108e5 to your computer and use it in GitHub Desktop.
xscreensaver-wait-for-unlock
#!/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
@ivan
Copy link
Author

ivan commented Dec 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment