Search

Top Posts

Comments

  • ZAYIFLAMA YOLLARI: Zayıflama Yolları, diyet listesi,rejim
  • Dan: You’d definitely need a microphone, mic stand and usb audio interface for a start!
  • Sepp: Mac OS X comes with an even more powerful Firewall than the one in the system preferences. Open up the Terminal...
  • jeffcard: Nice guide, thanks for sharing, here is a step by step guide regarding how to convert DVD, video and audio,...
  • James: Well, it hasn’t crashed on me yet, and I’ve been using it for at least 2 months now…

Categories

Recent Posts


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!

Posted by: Bill Ellis

Share

Save big on Mac Deals from Amazon.com

Comments:

Comments: 14

Comment from Andrew
Time: April 28, 2007, 7:32 am

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…

Comment from Weaver
Time: April 28, 2007, 10:37 am

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

Comment from Jerrome
Time: May 3, 2007, 2:08 am

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.

Comment from Kevin
Time: May 14, 2007, 8:11 am

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

Comment from Jay Valambhia
Time: November 15, 2007, 4:27 am

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

Comment from clitor
Time: January 12, 2008, 3:28 pm

excellent comands

Comment from shaun
Time: February 4, 2008, 8:50 pm

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

Comment from Amos
Time: February 5, 2008, 6:23 pm

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.

Comment from tim
Time: April 2, 2008, 10:13 am

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.

Comment from Kevin Bacon
Time: December 14, 2008, 9:04 pm

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.

Comment from Øyle
Time: January 14, 2009, 8:20 am

http://xkcd.com/530/

Comment from Don Gilbert
Time: July 6, 2009, 1:01 pm

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

Pingback from XKCD Puzzle « What Happens If I…
Time: November 22, 2009, 8:10 pm

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

Write a comment






April 28th, 2007