A command-line utility to control sound devices on macOS, written in Swift.
This utility controls the sound devices for macOS. You specify the name of the sound device, such as "Built-in Output", and the utility switches the device immediately without any GUI interaction.
This is a command-line utility only and has no graphical user interface.
brew tap graysoncash/soundctl
brew install soundctlswift build -c release
cp .build/release/soundctl /usr/local/bin/Or use the Makefile:
make installsoundctl <subcommand> [options]- current (default): Show current audio device
- list: List all audio devices
- set
<identifier>: Set the audio device - next: Cycle to the next audio device
- mute
[action]: Control mute status
- --type, -t
<type>: Device type (input/output/system/all). Defaults to output. - --format, -f
<format>: Output format (human/cli/json). Defaults to human. (Applies tocurrentandlist)
soundctl current
# or just
soundctlOutput:
Someone's AirPods Max (XX-XX-XX-XX-XX-XX)
soundctl current --format jsonOutput:
{"id":108,"type":"output","name":"Someone's AirPods Max","uid":"XX-XX-XX-XX-XX-XX:output"}soundctl listsoundctl list --type inputsoundctl list --format jsonsoundctl set "MacBook Pro Speakers"soundctl set "XX-XX-XX-XX-XX-XX"soundctl set "93"The set command is smart and auto-detects the type of identifier:
- MAC address format (XX-XX-XX-XX-XX-XX): Matches via UID
- Numeric ID: Matches by device ID
- Anything else: Matches by device name
Priority order: MAC address β numeric ID β name (so a device named "123" can still be matched even if there's an ID 123)
soundctl nextToggle the mute state for the currently selected input (e.g., microphone):
soundctl mute toggle --type input
# or just
soundctl muteMute the input:
soundctl mute on --type inputUnmute the input:
soundctl mute off --type inputThis is useful on a hotkey, e.g., to mute your Teams or Zoom input.
- id: Numeric identifier assigned by macOS at runtime. Can change between reboots or reconnections.
- uid: Persistent unique identifier string (the MAC address for Bluetooth devices). This is the reliable identifier for matching devices.
You can optionally create a configuration file at ~/.config/soundctl/config.json to filter which devices appear in listings and when cycling with the next command.
{
"ignoreDevices": {
"names": ["Virtual Device", "Aggregate Device"],
"uids": ["00-00-00-00-00-00"]
}
}{
"includeDevices": {
"names": ["MacBook Pro Speakers"],
"uids": ["11-22-33-44-55-66"]
}
}Filter Priority: If includeDevices has any entries, only those devices will be shown (allowlist mode). Otherwise, ignoreDevices will be used to exclude devices (blocklist mode). Both filters support:
- names: Array of device name strings. Matches if the device name contains the string or vice versa.
- uids: Array of UID strings (or MAC addresses). Matches if the device UID contains the string.
- macOS 13.0 or later
- Swift 5.9 or later
MIT License - see LICENSE file for details.
Originally inspired by switchaudio-osx by Devon Weller.
Rewritten in Swift for improved macOS integration and maintainability.