Switch Audio Source

Hey Peter,

That's @ComplexPoint's code rather than mine.  :slight_smile:

I suggest you download and install this command-line tool:

AudioSwitcher.zip (107.1 KB)

Install it here:

/usr/local/bin/

Open a window in the Finder and type G

Paste the path string in the resulting dialog, and hit the GO button.

Drag the executable from the archive into that folder – you will be required to enter your password to do so.

Then you can run this macro and avoid having to mess with System Events.

Toggle Audio Output.kmmacros (2.5 KB)

Although the display in the Sound Preferences changes to reflect whether headphones are connected the actual underlying “Built-in Output” doesn't change, so the shell script doesn't need to check for headphones.

If the macro doesn't work out-of-the-box then the wording for C_Media USB Audio Device may be off.

You can check by switching to that output and then running this in the Terminal.app:

AudioSwitcher -c

The output should look something like this:

C_Media USB Audio Device (output)

If that differs from what I have in the shell script then you'll need to change it:

Remove (output) from the end of what you got from the terminal and replace the relevant string in the shell script in the macro.

All of this may seem a bit intimidating, but it's really simple to get done step-by-step.

Message me if you need help.

TESTED: on OSX 10.11.5 with Keyboard Maestro 7.2

-Chris

2 Likes