简体   繁体   English

在python中获取xscreensaver状态

[英]Get xscreensaver status in python

I'm running OpenSUSE Leap 42.3 with XFCE and it uses xscreensaver. 我正在使用XFCE运行OpenSUSE Leap 42.3,它使用xscreensaver。

I want to somehow get True if screensaver is currently working. 如果屏幕保护程序当前正在运行,我想以某种方式获取True。 You can't just look at process list, xscreensaver always sits there. 您不能只看进程列表,xscreensaver总是坐在那里。

Is there any easy way to do that? 有没有简单的方法可以做到这一点?

Use the subprocess module to run xscreensaver-command : 使用subprocess模块运行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. 这个简单的代码在输出中查找单词“ blanked”。 You could parse it further to extract the time it was activated/deactivated. 您可以进一步解析它,以提取其激活/停用时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM