Last Updated: February 25, 2016
·
27.15K
· nickrw

Set/get OSX volume/mute from the command line

I ended up wanting to do this when wrapping the OSX `say' command. I have a wrapper script on github which sets the volume and unmutes, runs the say command, restores the volume level and mutes again if appropriate.

Get volume

# Echos a number from 0 to 100
osascript -e 'output volume of (get volume settings)'

Set volume

# Where 50 is a number from 0 to 100
osascript -e 'set volume output volume 50'

Get mute state

# Echos a string of 'true' or 'false'
osascript -e 'output muted of (get volume settings)'

Set mute state

# Where 'true' can be 'true' or 'false'
osascript -e 'set volume output muted true'