【问题标题】:Get xscreensaver status in python在python中获取xscreensaver状态
【发布时间】:2018-03-01 13:21:26
【问题描述】:

我正在运行带有 XFCE 的 OpenSUSE Leap 42.3,它使用 xscreensaver。

如果屏幕保护程序当前正在工作,我想以某种方式获取 True。你不能只看进程列表,xscreensaver 总是在那里。

有什么简单的方法吗?

【问题讨论】:

  • 结帐man xscreensaver-command。 “工作”可能意味着覆盖屏幕或使用登录对话框锁定屏幕,后者可能发生在前者之后,具体取决于配置。您可能需要轮询xcreensaver-command -watch 的输出。

标签: python linux python-3.x screensaver xfce


【解决方案1】:

使用subprocess 模块运行xscreensaver-command

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

这个简单的代码在输出中查找单词“blanked”。您可以进一步解析它以提取它被激活/停用的时间。

【讨论】:

    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多