问题
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