mac-volume: A CLI to control device volume
I’ve set my Mac up such that video calls such as Zoom use the microphone and earphones attached to my Behringer UMC204HD, which all other audio plays through the my normal speakers which are the default.
One issue I have with this is that it’s quite hard to change the volume when a call as the volume buttons on the Mac are connected to the default output. This finally annoyed me enough that I looked into how to control the volume of a device and wrote a little command line utility for this, so that I could attach it to buttons on my StreamDeck using Keyboard Maestro.
Changing the volume
The way to control the volume on a Mac programmatically is to use Core Audio, specifically AudioObjectSetPropertyData(). This function takes a deviceID and some other properties, including volume. The deviceID is of type AudioDeviceID and the volume is a floating point number between 0 and 1.
It’s not easy to remember device IDs, so I decided to use the device name instead and map the volume to between 0 and 100. This makes it easy to say set the volume to 10%:
mac-volume "MacBook Pro Speakers" set 10
To get the list of device names, I wrote a list-devices command. The list is available from AudioObjectGetPropertyData() which returns list of AudioDeviceID items. The name is in the kAudioObjectPropertyName selector, so that’s easy enough.
The main trouble is that CoreAudio is a C API and so dealing with it from Swift involves use of references and UnsafeMutablePointer which is a bit hairy as it’s been a while since I’ve had to worry about pointers!
Increment and decrement
While you can get the current volume, add to it and then set to increase the volume, it’s easier to let the app do it, so mac-volume also supports incrementing and decrementing by an amount. These are the two command that I bind to StreamDeck keys.

I found that a step size of 3 was a good choice for raising/lowering the volume with a reasonable number of presses of the key.
It’s on GitHub
If you need to control the volume of a non-default audio device from the command line, mac-volume is on GitHub at akrabat/mac-volume.