Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Change System Volume From Command Line

· 5 min read · Home Tech

In this article
  1. Why Use the Command Line for Volume Control
  2. Windows: Using NirCmd or PowerShell
  3. macOS: Using osascript
  4. Linux: Using amixer or pactl
  5. Choosing the Right Tool for Your OS
  6. Common Problems and How to Fix Them
  7. Frequently Asked Questions

Yes, you can change the system volume from the command line on Windows, macOS, and Linux. The exact command depends on your operating system and the tools you have installed, but each platform offers a built-in or widely available utility that lets you set, mute, or adjust the volume without touching the GUI.

Why Use the Command Line for Volume Control

Most people adjust volume through the speaker icon in the taskbar or menu bar. The command line becomes useful in several situations:

  • Scripting and automation: You can include volume changes in batch files, shell scripts, or scheduled tasks.
  • Remote sessions: When connected over SSH (especially on Linux servers with sound), a text command is the only way to change volume.
  • Accessibility: Users who rely on keyboard-only or screen-reader workflows may find command-line control faster.
  • Media players and hotkeys: Some custom hotkey tools execute command-line commands to adjust volume.

While the GUI is simpler for one-off changes, the command line shines when you need repeatable, precise control.

Windows: Using NirCmd or PowerShell

Windows does not include a built-in command-line tool specifically for volume control, but two reliable options exist:

Option 1: NirCmd (third-party, free)

NirCmd is a small command-line utility from NirSoft. Download it, place nircmd.exe in a folder (e.g., C:\Tools), and use these commands:

  • nircmd.exe setsysvolume 65535 — sets volume to maximum (65535 is the max value for the system volume).
  • nircmd.exe setsysvolume 32768 — sets volume to roughly 50%.
  • nircmd.exe changesysvolume -2000 — decreases volume by 2000 units.
  • nircmd.exe mutesysvolume 1 — mutes; use 0 to unmute.

The value range is 0 to 65535, which maps linearly to the 0–100% slider in Windows.

Option 2: PowerShell with COM (built-in)

PowerShell can control volume via the Windows Core Audio API, but it requires a bit of code. A common approach uses the SendKeys method to simulate volume keys, but that is unreliable. A more robust method involves loading the AudioDeviceCmdlets module (third-party) or using a small C# snippet. For most users, NirCmd is simpler and more direct.

macOS: Using osascript

macOS includes osascript, which can control the system volume through the System Events framework. Open Terminal and run:

osascript -e "set volume output volume 50"

This sets the output volume to 50 (on a 0–100 scale). You can also use:

  • osascript -e "set volume output volume (output volume of (get volume settings) + 10)" — increases by 10.
  • osascript -e "set volume output muted true" — mutes.
  • osascript -e "set volume output muted false" — unmutes.

Note that set volume without a specific output affects both output and alert volume. For precise control, always specify output volume.

Linux: Using amixer or pactl

Linux offers two main command-line tools, depending on the sound server:

ALSA: amixer

If your system uses ALSA directly (common in lightweight setups), use amixer:

  • amixer set Master 50% — sets the Master channel to 50%.
  • amixer set Master 10%+ — increases by 10%.
  • amixer set Master mute — mutes.

You may need to specify the correct card and channel if you have multiple audio devices.

PulseAudio/PipeWire: pactl

Most modern desktop Linux distributions use PulseAudio or PipeWire (which provides a PulseAudio-compatible interface). Use pactl:

  • pactl set-sink-volume @DEFAULT_SINK@ 50% — sets the default output sink to 50%.
  • pactl set-sink-volume @DEFAULT_SINK@ +5% — increases by 5%.
  • pactl set-sink-mute @DEFAULT_SINK@ toggle — toggles mute.

The @DEFAULT_SINK@ is a built-in alias for the default output device. If you have multiple sinks, list them with pactl list short sinks and specify the name.

Choosing the Right Tool for Your OS

Here is a quick summary of the recommended command for each platform:

  • Windows: Use NirCmd (third-party) for simplicity; PowerShell is possible but more complex.
  • macOS: Use osascript — built-in and reliable.
  • Linux (ALSA): Use amixer — works without a sound server.
  • Linux (PulseAudio/PipeWire): Use pactl — more modern and flexible.

If you are on Linux and unsure which tool to use, try pactl first because most desktop distributions use PulseAudio or PipeWire. If you get an error like "Connection failure: Connection refused", then PulseAudio is not running and you should fall back to amixer.

Common Problems and How to Fix Them

  • "Command not found" on Linux: The tool may not be installed. Install it with your package manager (e.g., sudo apt install alsa-utils for amixer, or sudo apt install pulseaudio-utils for pactl).
  • Volume changes but then reverts: Some applications override the system volume. Check if the app has its own volume control, or if a media key is being pressed.
  • Permission denied on macOS: Terminal may need Accessibility permissions. Go to System Settings > Privacy & Security > Accessibility and add your terminal app.
  • NirCmd blocked by antivirus: Some antivirus software flags NirCmd because it can control system functions. You can add an exception, or use PowerShell instead.
  • Volume changes but no sound: The volume may be set correctly, but the output device is muted or disconnected. Check the device state with pactl list sinks or the Windows sound settings.

Frequently Asked Questions

Can I change the volume without any third-party tools on Windows?

Yes, but it requires a PowerShell script that uses the Windows Core Audio API. You can write a small C# snippet or use a module like AudioDeviceCmdlets (third-party). For a one-liner, NirCmd is much easier.

What is the maximum volume value in NirCmd?

The maximum is 65535, which corresponds to 100% on the Windows volume slider. The mapping is linear: 32768 is 50%, 6553 is 10%, and so on.

How do I set volume to a specific percentage on macOS?

Use osascript -e "set volume output volume 75" to set it to 75%. The scale is 0 to 100, so percentages are direct.

Does changing volume via command line affect all apps or just the system?

On Windows, setsysvolume changes the system master volume, which affects all apps. On macOS, set volume output also changes the system output volume. On Linux, pactl set-sink-volume changes the sink volume, which is the master for that output device, affecting all apps playing through it.

Can I use these commands in a script to gradually fade the volume?

Yes. You can write a loop that increments or decrements the volume in small steps with a short delay. For example, on macOS, a bash loop can call osascript repeatedly. On Windows, a batch file with a loop and nircmd changesysvolume works similarly.

Is there a way to change the volume of a specific application, not the whole system?

Yes, but it requires more advanced tools. On Windows, you can use the AudioDeviceCmdlets PowerShell module or third-party apps. On Linux, pactl can set per-application volumes with pactl set-sink-input-volume. On macOS, this is not natively possible from the command line without third-party utilities.