How to change volume with Python?

断了今生、忘了曾经 提交于 2019-12-06 05:50:03

You can control the volume of your computer with Applescript:

set volume output volume 100

To execute Applescript from python you can use py-applescript which can be installed with sudo easy_install py-applescript. The following script will set the volume:

import applescript

applescript.AppleScript("set volume output volume 100").run()

EDIT: For Python3.6 you can use osascript instead: pip3.6 install osascript and:

import osascript

osascript.osascript("set volume output volume 100")

You do not need anything outside of the standard library to do this in python. Apple supports executing AppleScript from the terminal so the subprocess module is sufficient.

from subprocess import call
call(["osascript -e 'set volume output volume 100'"], shell=True)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!