Change the System Volume from the Command Line in Mac OS X

Apr 28, 2007 - 26 Comments

Terminal in OS X There are several ways to go about changing the volume on your Mac, but did you know you can use the command line? I’m a big command line junkie so the more things I can do from the Terminal the better. If you want to adjust your system volume level directly from the command line, you can do so with the ‘osascript’ command, which is basically a terminal front-end to AppleScript and all that it can do. For the purposes of changing system volume in just about every single version of Mac OS X ever to exist, here are the necessary commands:

Mute your Mac:

sudo osascript -e "set Volume 0"

Maximum volume:

sudo osascript -e "set Volume 10"

Middle-level volume:

sudo osascript -e "set Volume 5"

Both of these commands will ask for your root password because of the usage of ‘sudo’ which runs the osascript command as the administrator.

As you may have guessed, you can fill in other numbers in place of 0 and 10 for other sound levels too.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Bill Ellis in Command Line, Mac OS X, Tips & Tricks

26 Comments

» Comments RSS Feed

  1. Andrew says:

    Two things:

    You shouldn’t need to use sudo. “osascript -e ‘set Volume 5′” works fine for me in a non-admin account.

    And you aren’t limited to integers: “osascript -e ‘set Volume 4.5′” also works, so you could ramp the volume up or down slowly with a script…

  2. Weaver says:

    what I don’t understand about osascript is that it’s just a command line tool to run apple scripts, so it’s weird to me that it can be used for other things like this.

    very useful eithreway

  3. Jerrome says:

    True, osascript is the command line tool to run apple scripts. In fact it does nothing different here, it runs an apple script to set the volume.

  4. Kevin says:

    Two things:

    1. Like Andrew, I didn’t need sudo permissions for this. 10.4. YMMV.
    2. I found it fun to combine this with a few other commands.
    a. SSH into a coworker’s box.
    b. # osascript -e “set Volume 10″
    c. # say -v Whisper “Why are you checking personal email on company time?”

    It gets interesting results. ;)

  5. Jay Valambhia says:

    Why bother with osascript with scutil and diskutil commands work a charm.

    Just type the following:

    Set Bonjour Name
    sudo scutil –set LocalHostName volume_name

    Set Sharing Name
    sudo scutil –set ComputerName volume_name

    Set Hard Disk Name
    diskutil rename /Volumes/ volume_name

    Smoother and effiicient.

    Jay

  6. clitor says:

    excellent comands

  7. shaun says:

    Just want to point out that the “set volume x” is deprecated… Instead use

    $ osascript -e “set volume output volume 100″

    or any value between 0 and 100

  8. Amos says:

    Max volume actually appears to be 7. At least, if you work your way down from 10, 6 is the first one that is less on the displayed volume graphic.

  9. tim says:

    Is there a way to run the volume command at shutdown? I don’t always remember to mute before shutting down. Being a student sometimes in class or a library the start up sound can be annoying.

  10. Kevin Bacon says:

    To disable the startup sound do this:

    First write a small script:

    #!/bin/tcsh -f
    osascript -e ‘set volume 0′

    I named mine mute.sh and saved it to /usr/local/bin/. Next, make it executable:

    sudo chmod u+x /usr/local/bin/mute.sh

    Add it as a logout hook using the defaults write command:

    sudo defaults write com.apple.loginwindow LogoutHook /usr/local/bin/mute.sh

    And last, make a small AppleScript with Script Editor to set the sound back to a normal level when the user logs back in.

    set volume 3

    Save it as a run-only application, and add it to your login items. Restart and listen to the startup sound, because you won’t have to hear it again.

  11. Don Gilbert says:

    @ Jay – What your suggesting is changing the Disk Volume Name. This is not what the command is used for. The command is used to set the Volume on the system speakers.

    Reading you post was good for something though, it made me laugh. lol 

  12. […] Sometimes XKCD presents puzzles or problems to its listeners. Today’s puzzle was a particularly straight-forward one: googling for “mac os x command-line volume” led me straight to this answer. […]

  13. […] 1. you aren’t limited to integers, 1.5 would also work 2. original article […]

  14. chuck says:

    well if you read the man pages: Enter one line of a script. if -e is given, osascript will not look for a filename in the argument list.
    it is executing a script, set volume 10, but a one liner, and you have to put the proper qoutation marks.

  15. Matt says:

    Is it possible to lock the output volume limit? I can’t keep my kid from cranking up the volume when listening to iTunes with earbuds.

    • Oscar the Grouch says:

      You are asking technology to solve a social issue. Invariably this approach leads to failure. Please review your strategy.

      HINT: it’s a communications issue. Try actually TALKING to your child.

  16. Jon says:

    Can you go past maximum volume with this? It drives my crazy when I try to watch a movie while I wait around the airport and have to boot into windows to hear what’s going on (Windows plays sound louder for some reason)

  17. Dustin Kick says:

    osascript -e “set volume 11″

    # :D

  18. […] discussed how to change the Mac sound volume from the command line before and this tip uses the same commands to remotely adjust the system […]

  19. dupe says:

    hm …nice …is there a way to set the step size of the volume keys ?? like the alt+shift+volume key +/- ..i would like to have the changes more smooth coz i have active speakers …thx ..

  20. dfjdlfdfjk says:

    ‘sudo’ is not recognized as an internal or external command, operable program or batch file”

  21. Chris says:

    I used this to make a little script to easily change the volume. Using an admin account on OS X Mavericks, I don’t seem to need to use sudo to use osascript. If you just copy and paste this into your terminal it should install a command called volume, which you can use like “volume 10″, where the number is between 0 and 100, inclusive, and can have a decimal point:

    touch volume; echo -e “\x23\x21/bin/bash\nosascript -e \”set volume output volume \$1\”\n” >> volume; chmod +x volume; mv volume /usr/local/bin/

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates