February 9, 2022

Automating Default Audio Configurations on a Mac

Usually, tools like WebEx, BBB, Zoom, etc. tend to use the system’s default audio settings. This is nice if you use the same audio devices all the time. But, if you use different audio devices at home, in the office, or when traveling, you have to manually adjust the default audio settings often. (Or worse: you forgot to set the default settings and must adjust the audio settings in the conference tool for each call…) This repeated switching between configurations is annoying and time consuming.

The other day I (re)discovered an interesting tool: Hammerspoon.

Hammerspoon can interface with the Mac and provides an API to trigger/set various Mac functions/settings. I played with the tool a while ago but forgot about it as I didn’t really “need” it back in the day. After the rediscovery my idea was to test if you can use it to automate audio configuration for simplified switching between devices. And yes, you can:

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
  inDevice = hs.audiodevice.findInputByName("Home_Headset_Name")
  outDevice = hs.audiodevice.findOutputByName("Home_Headset_Name")
  outDeviceEff = hs.audiodevice.findOutputByName("MacBook Pro-Lautsprecher")
  hs.alert.show("Sound setting: Home Office")

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "O", function()
  inDevice = hs.audiodevice.findInputByName("Office_Headset_Name")
  outDevice = hs.audiodevice.findOutputByName("Office_Headset_Name")
  hs.alert.show("Sound setting: Office")

-- Reload config and spoons automatically
-- https://www.hammerspoon.org/go/#smartreload

Now, my home office settings will be activated when I press CMD + ALT + CTRL + H, for instance. Other configurations can be created analogously as you see. In case you wonder what setDefaultEffectDevice() means: this takes care that system sounds are played back on the Macbook’s speakers.

© ho1ger 2015 - 2022