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

Apr 28, 2007 - 29 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.

Adjust the System Volume from Command Line on Mac

For the purposes of changing system volume via Terminal in just about every single version of Mac OS X ever to exist, here are the necessary commands:

Mute your Mac:

This turns volume to 0, effectively muting the Mac speaker output:
sudo osascript -e "set Volume 0"

Maximum volume:

This sets the volume to the highest it will go:
sudo osascript -e "set Volume 10"

Middle-level volume:

This is about midrange audio output:
sudo osascript -e "set Volume 5"

Each 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. Try it out yourself, or choose a number that works for the speaker volume you are aiming for.

.

Related articles:

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

29 Comments

» Comments RSS Feed

  1. Matthew E says:

    It’s the smart quotes that are a problem?

    Works: osascript -e “set Volume 10″…

  2. Dimitar Nestorov says:

    For me “set Volume 7” resulted at 100% volume
    You can verify with running:
    osascript -e “get volume settings”

    I prefer this one:
    osascript -e “set volume output volume 100”
    osascript -e “set volume output volume 87”
    osascript -e “set volume output volume 50”
    osascript -e “set volume output volume 0”

    It’s actual percentage.

    Also if you want to mute (preserves volume):
    osascript -e “set volume output muted true”

    And unmute:
    osascript -e “set volume output muted false”

  3. 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/

  4. dfjdlfdfjk says:

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

  5. 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 ..

  6. […] 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 […]

  7. Dustin Kick says:

    osascript -e “set volume 11”

    # :D

  8. 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)

  9. 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.

  10. 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.

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

  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. 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 

  14. 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.

  15. 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.

  16. 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.

  17. 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

  18. clitor says:

    excellent comands

  19. 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

  20. 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. ;)

  21. 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.

  22. 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

  23. 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…

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

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

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site