All pastes #715840 Raw Edit

travis

public text v1 · immutable
#715840 ·published 2007-09-26 14:48 UTC
rendered paste body
#!/bin/bashexport 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]')thenexport ON_X_TTY=1elseexport ON_X_TTY=0fi# lid button pressed/released event handlertest -x /usr/sbin/laptop_mode && /usr/sbin/laptop_mode autoif grep -q open /proc/acpi/button/lid/LID/statethenchecktty	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	fielsechecktty	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	fifi