Skip to main content

#Shell - Set sound volume from the command-line

Add the next function and its corresponding alias to a shell startup script to set sound volume from the command-line. Thanks to Nick Robinson-Wall for sharing how to set/get/mute volume from the command line with .

function set_sound_volume() {
    local PERCENTAGE="${1}"       
  
    echo 'About to set volume up to '"${PERCENTAGE}"' % of its maximal value'  
    osascript -e 'set volume output volume '"${PERCENTAGE}"
}
alias set-sound-volume='set_sound_volume'