1
0
Fork 0
dotfiles/desktop-bin/xscreensaver-watchd

43 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Invoke script on xscreensaver state change
#
# Copyright (C) 2013 Mike Gerwitz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This simplifies hooking xscreensaver by having a script invoked with each
# state change rather than having to deal with daemon code. Since the script
# (and its executable check) is invoked with each and every state change,
# this has the pleasent and familiar benefit of allowing the user to change
# the script at any point in time without restarting the daemon.
#
# All output from the invoked script is redirected to stderr for logging.
#
# The -watch data is output back to stdout so that it may be used as a part
# of a pipeline in place of xscreensaver-command -watch.
##
# if no script is given as the first argument, default to a standard script
# name in the user's home directory
cmd="${1:-$HOME/.xscreensaver-watch}"
log="${2:-$HOME/.xscreensaver-watch.log}"
# -watch provides data in the format <state> <ts>; we will invoke the script
# once for each line of input, passing those data as two arguments
xscreensaver-command -watch | while read state ts; do
[ -x "$cmd" ] && "$cmd" "$state" "$ts" >&2
echo "$state $ts"
done