使用osascript设置变量

时间:2016-01-31 21:10:42

标签: python

我试图编写一个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'

1 个答案:

答案 0 :(得分:1)

这是您使用check_output的地方。

from subprocess import check_output
ovol = check_output(['osascript', '-e', 'get volume settings'])
print ovol

现在您只需要解析从'获取音量设置返回的字符串'。