我试图编写一个Python脚本来将我的Mac的音量级别作为一个我可以操作的变量:几乎完全是this。但是当我尝试从shell运行相同的命令时,我似乎无法将变量设置为新值。
>>> ovol = "dummy"
>>> call(['osascript', '-e', 'set ovol to output volume of (get volume settings)'])
88 #this is correct
0 #not sure where this comes from
>>> ovol
'dummy'
答案 0 :(得分:1)
这是您使用check_output
的地方。
from subprocess import check_output
ovol = check_output(['osascript', '-e', 'get volume settings'])
print ovol
现在您只需要解析从'获取音量设置返回的字符串'。