How to make custom OSX hotkeys

GUIs are just too slow!

Posted by Ben Zhao on February 25, 2023 · 2 mins read

You have a task, command, or workflow that you do regularly. The minimal effort it takes to open a setting and navigate to the audio output tab to switch output devices is ever-so-slightly too effortful and irksom. Also, there’s so much data in those GUIs for your eyes to parse, it’s like playing Where’s Waldo every time. That simply won’t do! You want–no, need–a hotkey to do it from anywhere in less than a second. This post will walk through how to set up a hotkey for the aforementioned audio switching workflow, but can be generalized for any workflow.

Create the action

Open the Automator app:

  1. Select “Quick Action”
  2. Choose Workflow receives no input in any application. Choose Action for the Image field.
  3. In the actions list, scroll down to find Run Shell Script. Drag and drop the action into the flow.
  4. Write whatever shell code you want to run in the box. I’m using SwitchAudioSource -i 102 > /dev/null which sets my audio to my headphones.
  5. Test it out by clicking the play button at the top right.
  6. Save the action with CMD+S and give it a name!

Tips: SwitchAudioSource is part of the switchaudio-osx package which can be installed by running brew install switchaudio-osx. The shell may also require the full path to the binary which can be obtained using the which command:

$ which SwitchAudioSource

Map the action to the keyboard

Open System Preferences:

  1. Navigate to Keyboard and click the Shortcuts tab.
  2. Select Services and scroll down until you find the name of the action you created in Automator.
  3. Click Add Shortcut to bind a keyboard shortcut to your action.
That's it. Now go live your best life ❤️