Adjust OSX System Audio Volume in Python

匆匆过客 提交于 2019-12-01 08:42:11

问题


I would like to adjust the system audio volume in OSX from a python script. This question about implementing keyboard shortcuts tells me how to do it in applescript, but I'd really like to do it from my python script without using os.system, popen, etc. Ideally I'd like to ramp up the volume slowly with some python code like this:

set_volume(0)
for i in range(50):
  set_volume(i*2)
  time.sleep(1)

回答1:


Use appscript to control the StandardAdditions scripting addition set volume command:

>>> from osax import *
>>> import time
>>> sa = OSAX()
>>> for i in range(50):
...   sa.set_volume(i*2)
...   time.sleep(1)
... 
>>> 


来源:https://stackoverflow.com/questions/2565204/adjust-osx-system-audio-volume-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!