I work fully remote and spend a lot of my day in videocalls. Over the time, I've created a setup that works quite well for me:
- Apple AirPods as headphones, which allow me to concentrate better on calls than speakers
- A proper boom microphone for great voice quality
While it works quite well, there is a slight annoyance: Every time macOS connects the AirPods, they automatically become the microphone as well, even though they have a worse quality. Also, using AirPods as pure speakers also increases their sound quality.
In this post, I'd like to show the small solution I built to solve this for me.
Hammerspoon is a useful tool for macOS, which allows you to write desktop automations using Lua scripts.
Using the following script, I enforce using my USB microphone every time macOS changes it to the AirPods. It also plays a sound for me as indicator that the settings are correct now, as some software (cough Microsoft Teams cough) doesn't like it, when these settings are changed during calls.
To use it, copy the script above into your
~/.hammerspoon/init.lua and reload the config. Don't forget to change the device name, you can find it in the system settings.
The old version
You can find the first version I originally wrote below, which was written using bash and a command line tool.
Compared to the new Hammerspoon version above, this version causes a spike in CPU load every few seconds, because it accidentally wakes up services like ContinuityCaptureAgent.
The version using Hammerspoon is reacting to events from macOS, which makes it more energy efficient and quicker to react.
After researching for quite a while, I found a useful cli tool called SwitchAudioSource, that allows to control sound devices on macOS.
You can install it using Homebrew:
The fix script
The following script runs a constant check loop and queries the current audio devices every 2 seconds. If the AirPods are connected and configured as audio input, it changes the input to the microphone and plays a sound as signal.
The sound is quite useful to me, as I wait for it after putting my AirPods on as indicator that everything is configured and I can join meetings safely.
If you want to use this script, don't forget to update the marked lines with the names of your devices. If you're unsure about the names, run the following command to see all connected devices:
Starting at boot
Running this by hand every boot is annoying, so let's integrate it into launchd, the macOS service manager.
You must adapt the marked paths in the file to your system, as launchd unfortunately doesn't support environment variables (like
$HOME) for these settings.
StandardOutPath are quite useful for debugging, but can be removed later if everything is working properly.
.plist file into
$HOME/Library/LaunchAgents/ and execute the following command:
Now connect your AirPods and wait for the signal. If it doesn't play within 3 seconds, check the output of the logfiles.
Stopping the service
To stop the service again, just unload the LaunchAgent: