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.
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.
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 ( ’ ).
This macro can be copied to create macros that set the Sound Output to other devices. For example:
- On my Mac mini (Mojave), the default is Internal Speakers. This macro can renamed to Set Sound Output - Internal Speakers.
- 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.
- 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.
By default, the AppleScript User Interface Scripting is set for English. If another Language is set under System Preferences Language & Region, these values will need to be changed within the first Execute AppleScript action.
This macro requires Keyboard Maestro v8.0.3+.
• Keyboard Maestro 10.0.2
• Monterey, v12.3.1/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445
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 successfully set.
2.0 a) Checks the running state of System Preferences before running the AppleScript that changes the Sound Output. b) In the AppleScript: i) removed unnecessary System Preferences activate, ii) added localization locWindowSound and locButtonOutput.
2.1 - The embedded AppleScript now delays until a sound output radio button exists before it attempts to select it. This is done using: repeat until exists radio button locButtonOutput and two delay 0.1
2.2 - Fixed typographical errors in this comment. No functional changes to the macro.
DOWNLOAD Macro File:
Set Sound Output.kmmacros (34 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.