Created
January 9, 2014 05:53
-
-
Save ryo1kato/8329996 to your computer and use it in GitHub Desktop.
a wrapper for xscreensaver-command to behave like gnome-screensaver-command
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 | |
| # screen-saver wrapper to fix/modify xflock4 behavior | |
| # It also logs when it's activated. | |
| #logfile="$HOME/.screensaver.log" | |
| logfile="$HOME/usr/var/log/screensaver.log" | |
| control_command () { | |
| #gnome-screensaver-command "$@" | |
| /usr/bin/xscreensaver-command "$@" | |
| } | |
| start_screensaver_if_not () { | |
| if ! pgrep '^xscreensaver$' > /dev/null 2>&1 | |
| then | |
| echo "Starting xscreensaver" | |
| ( xscreensaver -no-splash 0<&- &>/dev/null & ) | |
| fi | |
| } | |
| dtparse () { | |
| python -c 'import sys; import dateutil.parser as p; h=sys.stdin.readline(); dt=p.parse(h); print dt' | |
| } | |
| ###################################################### | |
| datestring=$(date '+%Y%m%d-%H:%M:%S') | |
| LOG () { | |
| if [ -w $logfile ]; then | |
| echo "$datestring xscreensaver $*" >> $logfile | |
| fi | |
| } | |
| log_nonblank_since () { | |
| out=$(control_command -time) | |
| case "$out" in | |
| *"non-blanked since"*) | |
| echo "$(echo "$out" | sed -e 's/^.*since \(.*\) (.*$/\1/g' | dtparse | sed -e 's/-//g' -e 's/ /-/') non-blank since." >> $logfile | |
| ;; | |
| *) | |
| : ignore ;; | |
| esac | |
| } | |
| start_screensaver_if_not | |
| arg="$1" | |
| shift | |
| case "$arg" in | |
| -prefs) $pref_command -prefs;; | |
| -cycle|-next|-prev|-exit) : ignore ;; | |
| -log) | |
| log_nonblank_since;; | |
| -lock) | |
| log_nonblank_since | |
| #control_command "-activate" | |
| control_command "-lock" | |
| LOG "locked" | |
| ;; # lwsmd issue. | |
| -activate|-deactivate) | |
| control_command $arg | |
| LOG "${arg#-}" | |
| ;; | |
| -demo|-time|-prefs) control_command $arg "$@";; | |
| *) echo "$0: Unrecognized command: $arg" >&2 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment