0

I'm running OpenSUSE Leap 42.3 with XFCE and it uses xscreensaver.

I want to somehow get True if screensaver is currently working. You can't just look at process list, xscreensaver always sits there.

Is there any easy way to do that?

fayobace
  • 1
  • 1
  • Checkout `man xscreensaver-command`. "Working" could mean covering the screen or locking it with a login dialogue box, and the latter could happen after the former, depending on the configuration. You probably need to poll output of `xcreensaver-command -watch`. – Cong Ma Mar 01 '18 at 13:57

1 Answers1

4

Use the subprocess module to run xscreensaver-command:

def check_screensaver():
    p = subprocess.run(['xscreensaver-command', '-time'], stdout=subprocess.PIPE)
    words = p.stdout.decode().split()
    return 'blanked' in words

This simple code looks for the word 'blanked' in the output. You could parse it further to extract the time it was activated/deactivated.

nosklo
  • 217,122
  • 57
  • 293
  • 297