Set Sound Output

I found a post, Program to Switch Audio Output, as I was searching the Keyboard Maestro Forum for a method to quickly switch the macOS Audio Output. When I tried using switchaudio-osx as mentioned in the post, it didn't function for my Homepod or other AirPlay devices. Thus I created a macro that completes this task using AppleScript that automates the macOS User Interface.


Set Sound Output

PURPOSE
This macro sets the Macintosh Sound Output to a specified name. This can include Apple Homepods and other AirPlay devices. Note that this shortcut uses AppleScript that automates the User Interface, specifically the System Preferences. See Automating the User Interface (https://apple.co/3lj3PQB) for more information.

SETTINGS
By default, this macro will set the Sound Output to the Internal Speakers. This can be changed using the local__SoundOutputName variable. Note that this value is case sensitive and punctuation marks must exactly match the entries in the System Preferences > Sound > Output. For example, Jim’s Airpods Pro includes a smart apostrophe ( ).

MULTIPLE INSTANCES OF SET SOUND OUTPUT
This macro can be copied to create macros that set the Sound Output to other devices. For example:

  1. On my Mac mini (Mojave), the default is Internal Speakers. This macro can renamed to Set Sound Output - Internal Speakers.
  2. On my MacBook Pro (Big Sur), the default is MacBook Pro Speakers. This macro can be copied and renamed to Set Sound Output - MacBook Pro Speakers. The local__SoundOutputName variable will need to be adjusted.
  3. I have an Homepod in our home office. This macro can be copied and renamed to Set Sound Output - Homepod - Office. The local__SoundOutputName variable will need to be adjusted.

LIMITATIONS
This macro requires Keyboard Maestro v8.0.3+.

TESTED WITH
• Keyboard Maestro 9.2
• Big Sur 11.5.2 on MacBookPro16,1
• Mojave 10.16.6 on Macmini6,2

VERSION HISTORY
1.0 - Initial version
1.1 a) Succeeds even if it takes a few seconds for the System Preferences > Sound > Output list to populate with the available options. b) Displays an error dialog if the specified Sound Output is not succcessfully set.

DOWNLOAD Macro File:
Set Sound Output.kmmacros (18 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Images • Set Sound Output

2 Likes

I've updated the original post with version 1.1. This version:

a) Succeeds even if it takes a few seconds for the System Preferences > Sound > Output list to populate with the available options.

b) Displays an error dialog if the specified Sound Output is not succcessfully set.

1 Like