LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to make xset dpms force off work with gnome-power-manager (http://www.linuxquestions.org/questions/linux-software-2/how-to-make-xset-dpms-force-off-work-with-gnome-power-manager-880929/)

nokangaroo 05-16-2011 12:24 AM

How to make xset dpms force off work with gnome-power-manager
 
The following script should make screen blanking work without disabling gnome-power-manager:

#!/bin/bash
if [ ! -z $(pidof gnome-power-manager) ]; then
kill -HUP $(pidof gnome-power-manager)
fi
xset dpms force off


This script can also be called from a panel launcher (with ./<scriptname> if it is in $HOME). It will not disable the power manager even though the process disappears from the system monitor. The "if" condition is necessary because SIGHUP will return an error if the process doesn't exist.


If you want a bash command, add this to $HOME/.bashrc:

# The following cannot be implemented as an alias
# and it cannot be called from a launcher, more's the pity
dark ()
{
if [ ! -z $(pidof gnome-power-manager) ]; then
kill -HUP $(pidof gnome-power-manager)
fi
xset dpms force off
}

EricTRA 05-16-2011 12:36 AM

Hi,

Thank you for sharing. Off the Zero Reply List.

Kind regards,

Eric

corp769 05-16-2011 06:30 AM

Hello,

Is this a safe way of doing this?

Josh

nokangaroo 05-17-2011 12:00 AM

Other people have suggested to killall the power manager or run dpms in a loop, so this is hardly more exotic. Of course I am used to experimenting a lot, and prepared to restore from backup if necessary, so maybe not everybody would like to do everything I do.

As an alternative, you can install the Inhibit applet into your panel and click it before you run "xset dpms force off".

nokangaroo 05-18-2011 02:45 AM

How about this? I just learned about the existence of xdotool, which should make all kinds of neat tricks possible.
Edit: altered the script to work without sed and without a tempfile. The reply below still remains valid.

#!/bin/bash
#dark: the ultimate screen blanker

#test for necessary software:
if [ ! -e /usr/bin/xdotool ]; then
echo "You need to install xdotool for this crock to work!"
exit
fi

#get the sum of the x and y mouse coordinates (since we are not interested in the actual position but its change).
Since we are cursor movement we could read the entire output of "xdotool getmouselocation"
into a variable, see below (it is even possible to read a string that goes over several lines into a variable,
so INDEX=$(xdotool getmouselocation --shell) is also possible).
eval $(xdotool getmouselocation --shell)
INDEX=$(expr $X + $Y)

if [ -z "$INDEX" ]; then
#do we think that the Synaptic Package Manager has a monopoly on annoying error messages?
echo "something wicked happened ... read the xdotool manual"
exit
fi

#if power manager is not already dead, kill it:
if [ ! -z $(pidof gnome-power-manager) ]; then
killall gnome-power-manager
fi

#the actual work is done here:
xset dpms force off

#polling for cursor movement:
while :
do
eval $(xdotool getmouselocation --shell)
TEST=$(expr $X + $Y)
sleep 1
if [ "$TEST" != "$INDEX" ]; then

#restart power manager, without being annoyed by the "floating object" error message:
gnome-power-manager 2> /dev/null &
exit
fi
done

corp769 05-18-2011 02:51 AM

The only thing that I feel weird about is killing gnome-power-manager. So you are telling me that doing it that way is ok to do? I'm not coming off rude at all, I just think it's weird of doing it that way.

nokangaroo 05-18-2011 04:23 AM

The power manager is restarted once you move the mouse. The "floating object" error message you get is a memory leak bug in gnome-power-manager (against which a bug report has already been filed, so maybe we soon won't need workarounds like this script any more, hopefully). If you are uneasy about killing the power manager, use the Inhibit Applet. The computer won't go to sleep when you kill the power manager (or use the Inhibit Applet), but that is what you want when you let the computer run unattended (why else would you turn off the screen?). Maybe somebody could figure out how to call the Inhibit Applet from a script?

Actually, I thought people would comment on the many write operations to the tempfile while the script loops.
Edit:eliminated the tempfile.


Here is the same script in a version for ubuntu lucid:

#!/bin/bash
#dark: the ultimate screen blanker

#test for necessary software:
if [ ! -e /usr/bin/xdotool ]; then
echo "You need to install xdotool for this crock to work!"
exit
fi

#read mouse coordinates into a variable as a string (we are not interested in the actual coordinates but their change, and we read the entire xdotool output into the variable for simplicity)
INDEX=$(xdotool getmouselocation)

if [ -z "$INDEX" ]; then
#do we think that the Synaptic Package Manager has a monopoly on annoying error messages?
echo "something wicked happened ... read the xdotool manpage"
exit
fi

#if power manager is not already dead, kill it:
if [ ! -z $(pidof gnome-power-manager) ]; then
killall gnome-power-manager
fi

#the actual work is done here:
xset dpms force off

#polling for cursor movement:
while :
do
TEST=$(xdotool getmouselocation)
sleep 1
if [ "$TEST" != "$INDEX" ]; then

#restart power manager, without being annoyed by the "floating object" error message:
gnome-power-manager 2> /dev/null &
exit
fi
done


All times are GMT -5. The time now is 10:59 AM.