Posts: 21
Joined: Fri Nov 25, 2016 1:34 pm

Run Command or script on Screen Blank

Sat Apr 08, 2017 10:04 am


I have been scouring the web to try and find this but I keep getting topics explaining how to stop the screen from blanking. I do want my screen to blank after 5 minutes of use and turn of my monitor. I also want to run a script so I can turn off my monitor (which doesn't seem to want to by it self when my pi blanks the screen) and then turn it on again after the blank.

Is there a place where I can specify this in a config file or do i need to disable screen blanking and write a script that listens for mouse or keyboard input over a period of time and do this that way?

I'm running on a RPI3, Jessie with Pixel, and using a Pi-Top.

Thanks in advance

Posts: 198
Joined: Wed Dec 14, 2016 10:47 am
Location: Germany

Re: Run Command or script on Screen Blank

Sun Apr 09, 2017 12:58 pm

What did you try so far? Does xset help: ? Frank

Posts: 21
Joined: Fri Nov 25, 2016 1:34 pm

Re: Run Command or script on Screen Blank

Sun Jul 02, 2017 6:54 pm

I made the following python script that autostarts on my PiTop:

Code: Select all

import os, subprocess, time
cmdMonitor = "xset q | grep -oP "'"Monitor is \K.*"'""
cmdSetBright = "brightness %d | grep -oP "'"Current brightness = \K.*"'""
cmdOffBright = "brightness off | grep -oP "'"Current brightness = \K.*"'""

Monitor_old = "On" 
global Brightness_Old

while 1:
    Monitor = subprocess.check_output(cmdMonitor, shell=True)
    Monitor = Monitor.translate(None, chr(10)+chr(5))
    if Monitor != Monitor_old:
        if 'Off' in Monitor:
            Brightness_Old = int(subprocess.check_output(cmdOffBright, shell=True))
        if 'On' in Monitor:
            subprocess.check_output(cmdSetBright % Brightness_Old, shell=True)
        Monitor_old = Monitor
I'ts not pretty, but it works. My solution was to continuously poll the status of the monitor to determine if the screensaver was on. I was hoping for something more interrupt or event driven, but beggars can be choosers.

Return to “Raspbian”