0

How can I wait until xscreensaver is unlocked? xscreensaver-command -lock locks the screen, but it returns before the screen is unlocked again. xscreensaver provides an xscreensaver-command -watch to print UNBLANK events, but how do I parse them and make sure xscreensaver-command -watch is killed afterwards?

0

This program will exit after xscreensaver is unlocked (or "unblanked" after an activation that does not require a password):

#!/bin/bash

set -eu

FIFO=/tmp/xscreensaver-wait-for-unlock-$$.fifo
rm -f "$FIFO"
mkfifo "$FIFO"

# Kill `xscreensaver-command -watch` when we exit
trap "exit" INT TERM
trap "kill %1; rm -f $FIFO" EXIT

xscreensaver-command -watch > $FIFO &

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 < $FIFO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.