Change the system volume from the command line
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. Without further ado, here’s the necessary commands:
Mute your Mac: sudo osascript -e "set Volume 0"
Maximum volume: sudo osascript -e "set Volume 10"
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. Enjoy!

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…
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
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.
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.
[...] http://osxdaily.com/2007/04/28/change-the-system-volume-from-the-command-line/ http://textsnippets.com/posts/show/285 [...]
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
That’s not what this is talking about! It’s talking about sound volumes, not drive volumes.
excellent comands
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
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.
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.
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.
http://xkcd.com/530/
@ 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
@Don yup, I wonder as well why he mentioned scutil … it’s not the disk volume, instead just the sound … :-p
[...] 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. [...]
[...] 1. you aren’t limited to integers, 1.5 would also work 2. original article [...]
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.
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.
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.
Hey there, for reasons uknown when I put your rss into google reader, it will not work. Can you give me the RSS link just to make certain I’m using the right one?
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)
osascript -e “set volume 11″
#
[...] 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 [...]
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 ..
‘sudo’ is not recognized as an internal or external command, operable program or batch file”