我正在使用Ubuntu 16.04我正在寻找一个表单来关闭ubuntu通知。我找到了下面的脚本,但是当我运行它时,我收到了错误:
Traceback (most recent call last):
File "manage_notifications.py", line 6, in <module>
["xrandr"]).decode("utf-8").split() if "+0+0" in s][0]
IndexError: list index out of range
有谁知道出了什么问题? 剧本:
#!/usr/bin/env python3
import subprocess
import time
w = int([s.split("x")[0] for s in subprocess.check_output(
["xrandr"]).decode("utf-8").split() if "+0+0" in s][0]
)
def get_mouse():
loc = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()[:2]
return [int(n.split(":")[1]) for n in loc]
while True:
time.sleep(1)
try:
subprocess.check_output(["pgrep", "notify-osd"]).decode("utf-8")
curloc1 = get_mouse(); t = 1
while t < 10:
time.sleep(1)
curloc2 = get_mouse()
test1 = curloc1[0] > w - 400 and curloc1[1] < 400
test2 = curloc2[0] > w - 400 and curloc2[1] < 400
if all([test1 == False, test2 == True]):
subprocess.Popen(["pkill", "notify-osd"])
break
curloc1 = curloc2
t = t+1
except:
pass
[输出编辑]:xrandr的输出:
me@my_pc:$ xrandr
Screen 0: minimum 8 x 8, current 2732 x 768, maximum 32767 x 32767
LVDS1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 309mm x 173mm
1366x768 59.97*+
1360x768 59.80 59.96
1280x720 60.00
1024x768 60.00
1024x576 60.00
960x540 60.00
800x600 60.32 56.25
864x486 60.00
640x480 59.94
720x405 60.00
680x384 60.00
640x360 60.00
DP1 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
VGA1 connected 1366x768+1366+0 (normal left inverted right x axis y axis) 410mm x 230mm
1366x768 59.79*+
1280x720 60.00
1024x768 75.08 75.03 60.00
832x624 74.55
800x600 75.00 60.32 56.25
640x480 75.00 60.00
720x400 70.08
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
我是否需要更改python脚本中的内容以匹配我的机器配置?