This macro/subroutine, when executed from another macro using the Execute a Macro action, 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 (Monterey or earlier) or System Settings (Ventura+). See Automating the User Interface (Mac Automation Scripting Guide: Automating the User Interface) for more information.
If this subroutine is called using Execute a Subroutine action, additional features are provided that can be useful if the macro is combined with Set Sound Input. See PARAMETERS below.
Sound Output Name :
Note that any spaces and punctuation marks must exactly match the entries in the System Preferences (or System Settings) > Sound > Output. For example, Jim’s AirPods Pro includes a smart apostrophe ( ’ ).
Save Initial State :
0 (No); 1 (Yes)
This saves, in a persistent Dictionary, the Open|Closed state and, if Open, the Displayed Pane. This value can then be retrieved by another instance of Set Sound Output (SSO) or the sister macro Set Sound Input (SSI).
Exit Action :
0 (Initial State, i.e., the state when SSO started; i.e., Open|Closed, if Open, which Displayed Pane)
1 (Saved State, i.e., the state saved in the Dictionary by SSO or SSI)
2 (Open–to the Sound pane)
This value specifies the action to be taken with the System Preferences (or System Settings) after the Sound Input is set.
If the macro is executed directly (e.g., from the Keyboard Maestro Editor), a dialog will appear that presents an option to create a calling macro. The dialog will prompt for the Sound Output Name. Note that any spaces and punctuation marks must exactly match the entries in the System Preferences (or System Settings) > Sound > Output. For example, Jim’s AirPods Pro includes a smart apostrophe ( ’ ).
If the Call As a Subroutine dialog checkbox is selected, the created macro will have the flexibility to use the SUBROUTINE PARAMETERS described above.
By default, the AppleScript User Interface Scripting is set for English. If another Language is set under System Preferences (or System Settings) Language & Region, the variable local_Pane needs to be set to Sound|Geluid|Ton (English, Nederlands, or Deutsch). Other languages could be easily added.
This macro requires Keyboard Maestro v10.0+.
• Keyboard Maestro v10.2
• Ventura Version 13.1 Beta (22C5033e)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445
( expand / collapse )
1.0 - Initial 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 successfully set.
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.
a) Added a check of %TriggerValue%. If it exists, it is used rather than the value hardcoded into local_SoundOutputName.
b) Added a check of macOS version. Unfortunately, with macOS Ventura (through 13.0 Beta 11—22A5373b), this macro will not function as expected. Hopefully this is a temporary issue during the beta period, but it could be an ongoing issue since in Ventura the macOS System Preferences have been moved the the System Settings.
a) Using the macOS version check added in v3.0, now conditionally runs a new AppleScript UI script compatible with Ventura. This was contributed by @ikenassi.
b) Based on a recommendation from @peternlewis, now opens the System Preference (pre-Ventura) or the System Settings (Ventura+) using the Open a System Preference Pane action rather than AppleScript.
c) When an error occurs, a message is displayed using Prompt For User Input rather than Display Text. With this change, the System Preferences (or System Settings) remain open when the error message is displayed.
d) Improved and simplified the localization in the AppleScript UI scripts: i) moved definition from AppleScript to the macro body, and ii) eliminated dependency on the word Output|Uitvoer|Ausgabe.
a) If the System Preferences (or System Settings) is already open to a pane, the macro returns to that pane.
b) Updated the TESTED WITH information.
a) To set the sound output, this macro now requires that it is executed by another macro using the Execute a Macro action. The Sound Output Name is set using the Execute a Macro With Parameter.
b) If the macro is run directly (e.g., from the Keyboard Maestro Editor), a dialog will appear that provides a option to create a calling macro.
a) For the created calling macros, no longer includes the Global Macro Trigger. It was a bit annoying to include this trigger, particularly for users that don’t use the Global Macro Trigger for other macros.
b) For the created calling macros, the method used to update the macro icon has been made more robust.
a) If the Sound pane does not open and properly populate, open the General pane, then open the Sound pane.
b) If AppleScript intially fails, wait 1.0 second and make another attempt.
c) Updated the error message dialog.
a) Compatible with Set Sound Input, v1.0 or later.
b) Changed to a subroutine with parameters: Sound Output Name, Save Initial State, Exit Action. The macro can still be run by another macro using Execute a Macro specifying the Sound Output Name in the With Parameter field.
• Save Initial State : 0 (No); 1 (Yes); This saves the Running State and the Displayed Pane (if Running) in a Dictionary. This value can then be retrieved by another instance of this macro or the sister macro Set Sound Input.
• Exit Action : 0 (Initial State, i.e., the state when SSO started; i.e., Open|Closed, if Open, which Displayed Pane); 1 (Saved State, i.e., the state saved in the Dictionary by SSO or SSI); 2 (Open–to the Sound pane); 3 (Close). This value specifies the action to be taken with the System Preferences (or System Settings) after the Sound Input is set.
c) If this macro is triggered from the KM Editor, a dialog will appear that provides an option to create a calling macro that will use the Execute a Subroutine action.
d) Sound Output changes are made more quickly and are less likely to fail. For example, if AirPods are specified, but they are in the case when the macro is launched, the macro will continue searching for a few seconds as the AirPods are removed from the case.
a) Support for macOS 14 (Sonoma): new AppleScript UI script compatible with Sonoma (slightly different than Ventura).
b) For the local__Exit Action 0I 1S 2O 3C = 2 condition, removed the Cancel Just This Macro action as I discovered that this does not function as expected when used within a subroutine. This action might be changed in a future version of Keyboard Maestro (reference).
If upgrading from an earlier version of Set Sound Output,
Upgrading from versions prior to Version 5.0
Keep your current Set Sound Output macros, but rename them by adding a suffix of "- OLD".
If you previously downloaded and installed the Toggle Sound Output, delete it.
Download and install the latest version of Set Sound Output.
Open one of your "- OLD" macros and copy the local_SoundOutputName to the clipboard.
From the Keyboard Maestro Editor, run the new version of Set Sound Output. You will see a dialog that will prompt you for your Sound Output Name. Paste the value you copied to the clipboard.
Click OK to dismiss the dialog. A simple macro will be created that executes Set Sound Output using the value you pasted. Optionally change the triggers.
Repeat Steps 4 to 6 for all of your "- OLD" macros.
Optionally download the latest version of Toggle Sound Output. Open it and set local_Sound Output Name 1 and local_Sound Output Name 2 as needed. Optionally change the macro triggers.
Once you test the new macros, delete the macros you renamed in Step 1.
Upgrading from Version 5.0 or later
From within the Keyboard Maestro Editor, delete your existing copy of Set Sound Output before you download and install the new version. On the other hand, do not delete your calling macros.
Download: Set Sound Output.kmmacros (181 KB)
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
- macOS 14.2 (23C5030f) PRE-RELEASE SEED SOFTWARE
- Keyboard Maestro v11.0