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.
Asked
Active
Viewed 1.0k times
4

slm
- 15,396
- 12
- 109
- 124
-
Possible duplicate of [Adjust OSX System Audio Volume in Python](https://stackoverflow.com/questions/2565204/adjust-osx-system-audio-volume-in-python) – Shriram Aug 19 '17 at 14:01
-
Looks similar to this: https://stackoverflow.com/questions/2565204/adjust-osx-system-audio-volume-in-python – Shriram Aug 19 '17 at 14:02
-
I also visited [Adjust OS X System Audio Volume in Python](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwiyhJP-xePVAhWld5oKHayHBHUQFggnMAA&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F2565204%2Fadjust-osx-system-audio-volume-in-python&usg=AFQjCNHVf4i2fu8KSNo6NrKguOCl5IeMrg) – Aug 19 '17 at 14:56
2 Answers
7
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")

clemens
- 16,716
- 11
- 50
- 65
-
thanks! I installed it by 'sudo pip3 install --trusted-host pypi.python.org py-applescript', but when importing it, "ModuleNotFoundError: No module named 'Foundation'". I also installed Foundation, but same error when importing. – Aug 19 '17 at 14:43
-
-
-
I asked it [here](https://stackoverflow.com/questions/45780836/how-to-control-volume-with-python3) – Aug 20 '17 at 11:09
-
4
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)

Dante
- 41
- 1