soulshined
Posts: 2
Joined: Tue Oct 18, 2016 5:08 pm

How to get Monitor Status (on/off) using DPMS flags or other

Tue Oct 18, 2016 5:20 pm

Is there a way to retrieve a monitors status (i.e, On/Off 1/0)?

Using:

Code: Select all

xset q
We are able to get a monitors status at the very bottom:
DPMS (Energy Star):
Standby:xxx Suspend:xxx Off: xxx
DPMS is enabled
Monitor is On
Is there a flag we can use to get only the Monitors status? I currently have a work-around in mind - writing xset q to a file, reading that file and checking for a substring of `Monitor is On` I really don't want to do that if there is an easier way. Or just a different way to do it that wont require me to go out of the terminal

Note: I checked this website for reference: https://www.x.org/archive/X11R7.7/doc/m ... et.1.xhtml

soulshined
Posts: 2
Joined: Tue Oct 18, 2016 5:08 pm

Re: How to get Monitor Status (on/off) using DPMS flags or o

Wed Oct 19, 2016 1:29 am

Nevermind, I ended up just going with my workaround. I put some timestamps on it and it all happened within a second. I can't argue a second is going to matter in my specific project. The only thing when testing I've found, is that it sometimes finds a false positive and says the monitor is off when it's not. I'm thinking that has to do with me not giving it enough time to write to the text file.

For those of you interested here is what I ended up doing:

Code: Select all

#This is the file where we will write a command line response to,
# in order to look for a substring in later
output_file="/home/pi/your_document.txt"

#xset q gets a complete status of current settings
# write the response to the file we chose
xset q > $output_file

#give time for the file to be written
sleep 1

#After the sleep is complete, we will search for the monitor status
# by looking for a specific string given in the response

if grep -F "Monitor is On" $output_file
then
  echo "Monitor status : On"
else
  echo "Monitor status: Off"
 #Force the monitor back on  
  xset dpms force on
fi
I just want to clarify this is not equivalent to shutting the monitor off through power, this is to get rid of the screensaver (which I want in my project)

Return to “Advanced users”