Reputation:
I'm writing a program to wake me up mornings, but I want my program to play alarm sound as loud as its possible. so it needs to raise up volume to 100%. but I don't know how. I'm using python3
on macOS Sierra.
Upvotes: 4
Views: 11456
Reputation: 51
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)
Upvotes: 5
Reputation: 17721
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")
Upvotes: 9