Change System Volume from Command Line on Mac OS

By  on  
Mac Volume

Oftentimes the awesome GUI applications we love are simply gloss over a command line functionality.  While I do love a visual app, it's always good to know how to do things from command line, if only for the sake of automation.  I've covered loads of command line secrets, most notably Mac Camera Access, so I wanted to figure out if I could control volume from command line.

Change Mac System Volume

The secret to changing Mac system volume from command line is through osascript:

# Max volume
sudo osascript -e "set Volume 10"

# Mute
sudo osascript -e "set Volume 0"

# 50% volume
sudo osascript -e "set Volume 5"

Values range from 0 (muted) to 10 (maximum volume).  Note that you don't get to see a nice volume change indicator -- the volume simply changes without any feedback.

Recent Features

  • By
    CSS vs. JS Animation: Which is Faster?

    How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point...

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

Incredible Demos

  • By
    dat.gui:  Exceptional JavaScript Interface Controller

    We all love trusted JavaScript frameworks like MooTools, jQuery, and Dojo, but there's a big push toward using focused micro-frameworks for smaller purposes. Of course, there are positives and negatives to using them.  Positives include smaller JS footprint (especially good for mobile) and less cruft, negatives...

  • By
    Facebook Sliders With Mootools and CSS

    One of the great parts of being a developer that uses Facebook is that I can get some great ideas for progressive website enhancement. Facebook incorporates many advanced JavaScript and AJAX features: photo loads by left and right arrow, dropdown menus, modal windows, and...

Discussion

  1. Akis

    Thank you for this tip. Are you sure that the maximum value is 10? On my Mac with High Sierra, the maximum value get on 7. The 8, 9, 10 also change the value to maximum. I did double check it by viewing the pop-up small window on volume indicator on menu bar.

  2. Simon Andersen

    This is how it’s done on Mojave:

    sudo osascript -e "set volume output volume [0-100]"

    The deprecated way is to specify a number between 0 and 7 for “set volume”

  3. Br. Bill

    Is there a way to similarly look up the current volume setting (let’s say, in Mojave or Catalina)?

  4. Syd Salmon

    Options to get the current volume setting:

    osascript -e 'output volume of (get volume settings)' # show current volume level

    or

    osascript -e 'get volume settings' # show all volume settings

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!