Development,  Tech Tips

Switch Audio Input/Output Device using Alfred

My top two must-have Mac apps are Keyboard Maestro and Alfred. If you know me, you’ve likely heard me say this, ad nauseum. I use these two apps countless times each day. Often I use them to run command line scripts via hotkey. This is one such implementation.

Recently I picked up a Jabra Evolve 65 headset. I keep it connected to my Mac via USB. Also, I have some speakers hooked up via the external speaker jack. You can only send output to one of these devices at a time (speakers OR headset). I desired a way to quick-switch between the two. I chose to use Alfred for this.

The steps below show how to create some quick switchers like this:

Alfred sound switchers

Switch to speakers

Requirements and Initial Setup

  1. Install https://github.com/deweller/switchaudio-osx (e.g., brew install switchaudio-osx )
  2. Run  which switchaudiosource  to see the full path to the binary
  3. Determine the names of your devices via switchaudiosource -a
  4. Find a good icon for the alfred workflow and the two triggers (a speaker and a headset should be fine; I use iconfinder to find free icons)

Alfred Workflow

Step 1: Create a new workflow

Name: Audio Switcher

Description: Switches audio input/output

Bundle ID: com.agileadam.alfredaudioswitcher

Created By: Adam Courtemanche

Website: https://www.agileadam.com

Step 2: Configure workflow and variables via the [x] icon at the top right of the workflow

Add About this Workflow text:

Step 3: Create the headset keyword trigger and action

Setup the Keyword

Right-click in the main area and choose Inputs » Keyword

Keyword = headset

Title = Switch to headset audio

Subtext = Send and receive audio from headset

Icon = headset icon from iconfinder.com (copy and paste into the icon box)

Setup the Action

Right-click in the main area and choose Actions » Run Script

Language = /bin/bash  with input as {query}  running instances Sequentially

Script =

Link the Keyword and the Action

Grab the handle on the right side of the headset Keyword object (when you hover you’ll see it).

Drag this over to the left side of the Run Script action object.

Step 4: Create the speakers keyword trigger and action

Setup the Keyword

Right-click in the main area and choose Inputs » Keyword

Keyword = speakers

Title = Switch to speakers

Subtext = Send audio to speakers

Icon = speaker icon from iconfinder.com (copy and paste into the icon box)

Setup the Action

Right-click in the main area and choose Actions » Run Script

Language = /bin/bash  with input as {query}  running instances Sequentially

Script =

Link the Keyword and the Action

Grab the handle on the right side of the speakers Keyword object (when you hover you’ll see it).

Drag this over to the left side of the Run Script action object.

Step 5: Try it out!

But Wait… There’s More

As I was writing this blog post I realized perhaps it’d be better to offer a third method, which would toggle the audio device.

I’ll let you decide what type of trigger you want to use for this one; I’m leaning towards a hotkey.

The script would be pretty simple:

3 Comments

  • Stuart moore

    Thanks, this was just what I was looking for.

    One tweak I’d suggest adding, is when setting up the Keyword, set ‘No Argument’ in the dropdown at top right. Otherwise Alfred will wait for a space and character before it’ll do anything.

    Cheers
    Stuart

  • Daniel

    Hi,

    I’m a huge fan of automation and an excessive AlfredApp user who also looked few times at Keyboard Maestro.
    Why are you using Keyboard Maestro AND Alfred?
    What unique features does Keyboard Maestro which aren’t included in Alfred?I’m really curious to see your use cases, to see what I have missed while my comparison.

Leave a Reply to Daniel Cancel reply

Your email address will not be published.