Install switchaudio-osx via Homebrew
masterYou can install the switchaudio-osx command-line utility using Homebrew.
brew install switchaudio-osxrepository·master·Indexed 23 days ago
https://github.com/deweller/switchaudio-osxA command-line utility for macOS that allows users to switch audio input and output sources, list available devices, and control mute status without using a GUI. It provides the SwitchAudioSource command to set devices by name, ID, or UID, and supports output formats in cli, human, and json.
You can install the switchaudio-osx command-line utility using Homebrew.
brew install switchaudio-osxThe SwitchAudioSource command allows you to switch the audio source on macOS via the command line. You can identify a device using its name (-s), its ID (-i), or its UID (-u).
Common flags:
-a: Show all available devices.-c: Show the currently selected device.-f <format>: Set output format to cli, human, or json (defaults to human).-t <type>: Set device type to input, output, or system (defaults to output).-n: Cycle to the next audio device.-s <device_name>: Set device by name.-i <device_id>: Set device by ID.-u <device_uid>: Set device by UID or a substring of the UID.You can control the mute status of audio devices using the -m flag. To target specific devices like a microphone, use the -t flag to specify the device type.
Supported mute modes for -m:
muteunmutetoggleExample: Toggle the mute state for the currently selected input device (e.g., a microphone):
SwitchAudioSource -m toggle -t inputThe following flags are available for the SwitchAudioSource command:
| Flag | Description |
|---|---|
-a | shows all devices |
-c | shows current device |
-f _format_ | output format (cli/human/json). Defaults to human. |
-t _type_ | device type (input/output/system). Defaults to output. |
-m _mute_mode_ | sets the mute status (mute/unmute/toggle). |
-n | cycles the audio device to the next one |
-i _device_id_ | sets the audio device to the given device by id |
-u _device_uid_ | sets the audio device to the given device by uid or a substring of the uid |
-s _device_name_ | sets the audio device to the given device by name |
switchaudio-osx command-line tool is invoked via the main entry point, which delegates execution to runAudioSwitch. This function processes command-line arguments (argc, argv) to perform audio device switching, muting, or listing operations on macOS. To use the tool, you must pass specific flags and arguments to the binary as defined in its CLI interface.