我想将此脚本转换为Python 3.5:
#!/bin/bash
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
while read x; do
case "$x" in
*"boolean true"*) source /home/user/bin/TV-Off.sh;;
*"boolean false"*) source /home/user/bin/Super-on.sh;;
esac
done
有可能吗
我找到了这个,但我不能让它工作。我收到Segmentation fault (core dumped)
更新
我想我可能已经做到了,但如果没有我注释掉的循环中的高处理器使用率,我似乎无法循环它。我还试图复制bash脚本,但运气不佳,但我觉得我遗漏了一些简单的东西
#!/usr/bin/python3.7
import dbus
#import time
count = 0
#while True: <---- First loop try high cpu
session_bus = dbus.SessionBus()
gnome_screensaver = 'org.gnome.ScreenSaver'
object_path = '/{0}'.format(gnome_screensaver.replace('.', '/'))
get_object = session_bus.get_object(gnome_screensaver, object_path)
get_interface = dbus.Interface(get_object, gnome_screensaver)
status = bool(get_interface.GetActive())
# print(status) <---- First loop try high cpu
# if status == True: <---- First loop try high cpu
# print("do something") <---- First loop try high cpu
# if status == False: <---- First loop try high cpu
# print("stopping") <---- First loop try high cpu
# count += 1 <---- First loop try high cpu
# time.sleep(10) <---- First loop try high cpu
# if count >= 500: <---- First loop try high cpu
# break <---- First loop try high cpu
x = status
#while x: <- Second loop try didnt work no output as screen goes black
if status == True:
print("do something")
if status == False:
print("stopping")
因此,经过进一步搜索,我在another post上找到了我需要的东西 所以我改变了一点
相关问题 更多 >
编程相关推荐