Revisions
-
mozbugbox created this gist
Aug 10, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #!/bin/bash # suspend/sleep linux system on xscreensaver activation # # run the bash script in your .xsession, # or something like .config/lxsession/LXDE/autostart for lxde timeout=60 # After xscreensaver activated, wait timeout to suspend read_timeout=5 # timeout for read from `xscreensaver-command -watch` SUSPEND_BIN=/usr/sbin/pm-suspend XSCREEN_CMD=/usr/bin/xscreensaver-command timeout=$(($timeout/$read_timeout)) blanked=0 timer=0 #echo $timeout # count down before suspend do_suspend() { timer=$(($timer + 1)) if [ ${timer} -ge ${timeout} ]; then timer=0 sudo ${SUSPEND_BIN} #echo "do suspend" fi #echo "timer: ${timer}" } process_watch() { # suspend after screen blank while : do # read xscreensaver -watch output read -t ${read_timeout} input if [[ $? -gt 0 && $? -lt 128 ]]; then break fi case "$input" in UNBLANK*) blanked=0 timer=0 ;; LOCK* | BLANK*) if [ ${blanked} = 0 ]; then blanked=1 timer=0 # restart timer fi ;; esac #echo "$input $blanked" # we are blanked, check do_suspend if [ ${blanked} -gt 0 ]; then do_suspend fi done } ${XSCREEN_CMD} -watch | process_watch