LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-16-2011, 12:24 AM   #1
nokangaroo
Member
 
Registered: Nov 2009
Posts: 135

Rep: Reputation: 23
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
}
 
Old 05-16-2011, 12:36 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hi,

Thank you for sharing. Off the Zero Reply List.

Kind regards,

Eric
 
1 members found this post helpful.
Old 05-16-2011, 06:30 AM   #3
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995
Hello,

Is this a safe way of doing this?

Josh
 
Old 05-17-2011, 12:00 AM   #4
nokangaroo
Member
 
Registered: Nov 2009
Posts: 135

Original Poster
Rep: Reputation: 23
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".
 
Old 05-18-2011, 02:45 AM   #5
nokangaroo
Member
 
Registered: Nov 2009
Posts: 135

Original Poster
Rep: Reputation: 23
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

Last edited by nokangaroo; 05-18-2011 at 09:24 PM.
 
Old 05-18-2011, 02:51 AM   #6
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995Reputation: 995
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.
 
Old 05-18-2011, 04:23 AM   #7
nokangaroo
Member
 
Registered: Nov 2009
Posts: 135

Original Poster
Rep: Reputation: 23
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

Last edited by nokangaroo; 05-18-2011 at 09:26 PM. Reason: Clarification
 
  


Reply

Tags
dpms, screen


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need script to autostart xset -dpms Kubuntu 10.04 cabman46 Ubuntu 13 07-25-2010 03:26 AM
xset dpms force on lowers my backlight redjokerx Linux - Laptop and Netbook 1 11-13-2007 10:55 PM
xset dpms force off does'nt turn off screen anirudh.iitm Linux - General 3 02-24-2007 01:54 PM
xset -dpms and xset s off ericcarlson Fedora 1 10-01-2004 07:45 AM
Slackware 8.1 and xset dpms problem. tchang Slackware 0 04-28-2003 10:53 AM


All times are GMT -5. The time now is 02:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration