TechEarl

How to Change the System Volume From the macOS Command Line

Set the macOS system volume from the terminal with osascript: the modern 0 to 100 scale, mute and unmute, reading the current level, input volume, and a one-line alias. No sudo needed.

Ishan Karunaratne⏱️ 6 min readUpdated
Share thisCopied
Set the macOS system volume from the command line with osascript on the 0 to 100 scale, mute and unmute, read the current level, and alias it for quick use.

To set the macOS system volume from the command line, run osascript against a one-line AppleScript:

bash
osascript -e 'set volume output volume 50'

That sets the output volume to 50 on a 0 to 100 scale, where 0 is silent and 100 is full. No sudo is needed: audio is part of your own login session, not a system-wide root setting. The change is instant and there is no on-screen volume HUD, which is exactly what you want when scripting it.

I keep this in a shell function because I reach for it constantly when a meeting starts and my speakers are still cranked from the night before. The whole thing is one osascript call, so it drops straight into any script, Automator action, or cron job.

Use the 0 to 100 scale, not the old 0 to 7 form

If you have seen the older set volume 7 form floating around, it still runs, but it is the legacy 0 to 7 scale and it is confusing. Values above 7 just clamp to maximum, so set volume 10 and set volume 7 do the same thing, and there is no way to tell from the command which scale you are on.

bash
# Legacy 0 to 7 scale (still works, but avoid it):
osascript -e 'set volume 7'

# Modern 0 to 100 scale (use this):
osascript -e 'set volume output volume 100'

The modern form is unambiguous because the keyword output volume names exactly what you are setting and the range matches what you see in System Settings. Always prefer set volume output volume N.

Mute and unmute

Muting is a separate state from a zero volume level. A muted Mac remembers its previous volume and restores it on unmute, whereas set volume output volume 0 sets the level to silent without flipping the mute flag.

bash
# Mute:
osascript -e 'set volume output muted true'

# Unmute:
osascript -e 'set volume output muted false'

The natural-language forms read the same way and are worth knowing if you see them elsewhere:

bash
osascript -e 'set volume with output muted'
osascript -e 'set volume without output muted'

Pick one style and stay consistent. I use the output muted true / false pair because it is the easiest to template into a script where the value comes from a variable.

Read the current volume

To read the current output volume rather than set it, ask for the volume settings and pull the field you want:

bash
osascript -e 'output volume of (get volume settings)'

That prints a single integer from 0 to 100. get volume settings returns a record with several fields, so you can read the mute state in the same call:

bash
osascript -e 'set v to get volume settings
"vol=" & output volume of v & " muted=" & output muted of v'

This is the piece that makes a real toggle possible: read the state, then decide whether to mute or restore.

Input and alert volume too

The same set volume command controls more than the speakers. input volume is the microphone gain, and alert volume is the system-sounds level, both on the same 0 to 100 scale:

bash
# Microphone input level:
osascript -e 'set volume input volume 75'

# System alert sounds (relative to output volume):
osascript -e 'set volume alert volume 30'

input volume is the one I use most after output: dropping the mic to 0 before a call is a faster mute than hunting for the right toggle in whatever app is running.

Alias it for quick use

Typing the full osascript line every time gets old fast. A tiny shell function takes a single argument and sets the output volume, so vol 20 is all you type. Add this to your ~/.zshrc (or ~/.bashrc):

bash
# Set macOS output volume on the 0 to 100 scale: vol 20
te_vol() {
  case "$1" in
    ''|*[!0-9]*) echo "usage: vol 0-100" >&2; return 1 ;;
  esac
  osascript -e "set volume output volume $1"
}
alias vol='te_vol'

Reload the shell (source ~/.zshrc) and vol 20 sets the output volume to 20. The case guard rejects anything that is not all digits before it reaches osascript, so a typo (or a stray argument) prints a usage line instead of being interpolated into the AppleScript string. You can extend the same pattern for mute with a second function, but for day-to-day use a single vol plus the bare mute and unmute one-liners covers most of what I need.

If you are wiring this into a larger macOS terminal workflow, the same osascript mechanism drives a lot of system settings. See the related guides at the bottom for toggling dark mode and setting the wallpaper from the command line.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsmacOSosascriptAppleScriptCLIterminalsystem volumemac

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts