我有点麻烦让这个代码工作。基本上,我想要的是检查wmctrl-l的输出是否有这个字符串:“Spotify-”。如果存在,请取消静音。如果它不存在,并且/或wmctrl-l包含一个名为“Spotify”的条目(行尾),那么我想静音。在
大部分代码都在工作,问题是GetWindowsPipe()只输出一行<open file '<fdopen>', mode 'rb' at 0x7f7a5f854660>
。不知道怎么回事。在
有人能帮我解决这个可能很简单的问题吗?在
代码:
import subprocess, time, pdb
def GetWindowsPipe():
pipe = subprocess.Popen("wmctrl -l", shell=True, stdout=subprocess.PIPE).stdout
return pipe
def LowerVolume():
subprocess.Popen("amixer -q set Master mute", shell=True)
print 'Lowering volume'
global volumeIsLow
volumeIsLow = True
def RaiseVolume():
subprocess.Popen("amixer -q set Master unmute", shell=True)
print 'Raising volume'
global volumeIsLow
volumeIsLow = False
def Run():
print 'Starting blockify.'
global volumeIsLow
volumeIsLow = False
RaiseVolume()
while(True):
found = False
pipe = GetWindowsPipe()
spot = "Spotify - "
if spot in pipe:
found = True
print 'found'
break
if found:
if (not volumeIsLow):
LowerVolume()
elif volumeIsLow:
RaiseVolume()
time.sleep(1)
if __name__ == "__main__":
Run()
这里有此脚本的扩展版本:http://pastebin.com/4RtTQCtf 我只是想让它重新工作,修剪一些脂肪。在
GetWindowsPipe()
返回管道对象,它是一个类似文件的对象。为了获得文本,您需要调用pipe.read()
。在您应该替换这个:
有了这个:
^{pr2}$相关问题 更多 >
编程相关推荐