#!/bin/bash export XAUTHORITY="$( ps --no-header -C xinit f|sed -e 's/.*-auth\ //' -e 's/serverauth.*/Xauthority/' )" export XUSER=$(ps -C startx -o user h) ##----------------------------------------------------- ##Debugging lines left in because two lines don't work! ##----------------------------------------------------- checktty() if test $(fgconsole) = $(ps --no-header -C X -o tty |grep -o '[0-9]') then export ON_X_TTY=1 else export ON_X_TTY=0 fi # lid button pressed/released event handler test -x /usr/sbin/laptop_mode && /usr/sbin/laptop_mode auto if grep -q open /proc/acpi/button/lid/LID/state then checktty if test $ON_X_TTY = 1 then echo "Xuser: $XUSER. In LID OPENED LOOP!" 1>&2 /usr/bin/xset -display :0.0 dpms force on su - $XUSER -c "/bin/grep ^dpmsOff:.*$ ~$XUSER/.xscreensaver" > .dpmsOff_val echo -e "Contents of \".dpmsOff_val\":\n" 1>&2;cat .dpmsOff_val 1>&2 su - $XUSER -c "/bin/sed -i 's/^dpmsOff:.*$/dpmsOff: 0:30:00/' ~$XUSER/.xscreensaver" su - $XUSER -c "DISPLAY=:0.0 /usr/bin/xscreensaver-command -restart" su - $XUSER -c "DISPLAY=:0.0 /usr/bin/xscreensaver-command -cycle" ##------------------------------------------------------------------------------------------------ ##This line doesn't work! Maybe a more advanced shell scripting programmer can fix it... su - $XUSER -c "/bin/sed -i 's/^dpmsOff:.*$/'$(cat .dpmsOff_val)'/' ~$XUSER/.xscreensaver" ##------------------------------------------------------------------------------------------------ rm .dpmsOff_val else /usr/sbin/vbetool dpms on fi else checktty if test $ON_X_TTY = 1 then echo "Xuser: $XUSER. In LID CLOSED LOOP!" 1>&2 su - $XUSER -c "/bin/grep ^dpmsOff:.*$" "$XUSER/.xscreensaver" > .dpmsOff_val echo -e "Contents of \".dpmsOff_val\":\n" 1>&2;cat .dpmsOff_val 1>&2 su - $XUSER -c "/bin/sed -i 's/^dpmsOff:.*$/dpmsOff: 0:00:10/' ~$XUSER/.xscreensaver" su - $XUSER -c "DISPLAY=:0.0 /usr/bin/xscreensaver-command -restart" /usr/bin/xset -display :0.0 dpms force off su - $XUSER -c "DISPLAY=:0.0 /usr/bin/xscreensaver-command -lock" ##------------------------------------------------------------------------------------------------ ##This line doesn't work! Maybe a more advanced shell scripting programmer can fix it... su - $XUSER -c "/bin/sed -i 's/^dpmsOff:.*$/'$(cat .dpmsOff_val)'/' ~$XUSER/.xscreensaver" ##------------------------------------------------------------------------------------------------ rm .dpmsOff_val else /usr/sbin/vbetool dpms off fi fi