繁体   English   中英

使用osascript设置变量

[英]Set variable using osascript

我正在尝试编写Python脚本来获取Mac的音量级别,作为我可以操纵的变量:几乎完全是this 但是,当我尝试从外壳程序运行相同的命令时,似乎无法将变量设置为新值。

>>> 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'

这是您要使用check_output

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM