MACRO: Set Sound Input, v1.0

PURPOSE

This macro/subroutine, when executed from another macro using the Execute a Macro action, sets the Macintosh Sound Input 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 Output. See PARAMETERS below.

SUBROUTINE PARAMETERS

Sound Input 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 Input (SSI) or the sister macro Set Sound Output (SSO).

Exit Action :
0 (Initial State, i.e., the state when SSI started; i.e., Open|Closed, if Open, which Displayed Pane)
1 (Saved State, i.e., the state saved in the Dictionary by SSI or SSO)
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.

CREATING A CALLING MACRO

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 Input Name. Note that any spaces and punctuation marks must exactly match the entries in the System Preferences (or System Settings) > Sound > Input. 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.

LOCALIZATION

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.

LIMITATIONS

This macro requires Keyboard Maestro v10.0+.

TESTED WITH

• Keyboard Maestro 10.2
• Ventura 13.3.1 (22E772610a)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445

VERSION HISTORY

1.0 - Initial version; compatible with Set Sound Output, v6.0 or later. For more information see: Using 'Set Sound Output' and 'Set Sound Input' Together


Download: Set Sound Input.kmmacros (158 KB)

Macro-Image

Keyboard Maestro Export


Macro-Notes
  • 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.

System Information
  • macOS 10.14.6 (18G9323)
  • Keyboard Maestro v10.2

Using 'Set Sound Output' and 'Set Sound Input' Together

When macros Set Sound Output (Version 6.0+) and Set Sound Input (Version 1.0+) are used together and called as subroutines, both sound settings can be set with minimal manipulation of the System Preferences (or System Settings).

For example, suppose the System Settings Privacy & Security pane is open. A macro that calls Set Sound Output (SSO) and Set Sound Input (SSI) could change the two settings and return to the Privacy & Security pane in just a few seconds.

Here are the steps:

  1. Both SSO and SSI can create macros that call themselves by simply executing them from the Keyboard Maestro Editor. For example, if SSO is executed from the editor, the following dialog appears:

2023-05-09 01.40.19

If MacBook Pro Speakers is entered, the following macro is created.

Keyboard Maestro Export

  1. Likewise, if SSI is executed from the editor, the following dialog appears:

2023-05-09 01.46.05

And if MacBook Pro Microphone is entered, the following macro is created.

Keyboard Maestro Export

  1. If the two macro are combined and the parameters are set as depicted, the combined macro would save the current state of the System Settings (in this hypothetical, open to the Privacy & Security pane), change the Sound Output, change the Sound Input, and return the System Settings to the initial state.

Keyboard Maestro Export


The Save Initial State and Exit Action parameters provide several other possibilities. Refer to the comments in the calling macros for more information.

1 Like