MACRO: Set Sound Output, v7.1

Thank you! This works perfectly! But I can't modify it so that I can toggle between speakers and Airpods that I often use. Could you please help?

1 Like

I've updated the OP with Version 2.1 of Set Sound Output:

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

Hi, @fom. You are welcome.

I just updated the macro to Version 2.1. Please download it and try again. This version should be somewhat more robust.

If you are still having a problem, please capture a screenshot of the dialog that appears and share it in this thread. For example, with the below screenshot I forced the macro to fail by setting local_SoundOutputName to Internal Speakers1.

2022-05-07 15.39.06

Hey,

Cool macro!

Have you thought about creating a keystroke that would toggle between two outputs? I am constantly changing between my external speakers and my headphones and want to be able to hit a keystroke to switch between them.

I found an Alfred workflow that does that really well, BUT for some reason now, my outputs change order in my Sound Preferences all the time.

I have two monitors with speakers that show up in there even though I never use them. I wish I could just remove them!

The Alfred workflow switches it based on the order in that pref panel rather than by name (like yours does).

I've updated the OP with Version 3.0 of Set Sound Output:

  • Added a check of %TriggerValue%. If it exists, it is used rather than the value hardcoded into local_SoundOutputName.

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

1 Like

Hi @BCBoarder. Thanks for the feedback. I'm glad that you are finding the macro useful.

Here's a macro that you can use to toggle between two values. Note that you will also need the latest version (v5.0) of Set Sound Output.


Download: Toggle Sound Output.kmmacros (10.0 KB)

Macro-Image


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 13.3.1 (22E772610a)
  • Keyboard Maestro v10.2

1 Like

Used this all the time, but can confirm that with Ventura 13.0 released version, it still does not function under Ventura. Keep up the great work!

1 Like

Hi, @spaceavian. Welcome to the Keyboard Maestro forum. Thanks for your report.

I'll add that it is still broken with macOS beta 13.1 (22C5033e).

Googling around I see that others have discovered this problem.

Interestingly, this AppleScript on a pre-Ventura system:

tell application "System Preferences"
  reveal pane id "com.apple.preference.sound"
end tell

gets converted (on Ventura in the Script Editor–when compiled) to:

tell application "System Settings"
  reveal pane id "com.apple.preference.sound"
end tell

(The conversion also occurs in a Keyboard Maestro Execute an AppleScript action.)

Although Preferences is automatically changed to Settings, the tell block fails on Ventura.

Same here. Fail!

1 Like

Yes, @ikenassi, I think it's safe to say that AppleScript related to the System Preferences (now Settings) is no longer functioning. We can hope that it might come back, but Apple's track record in such cases is not strong.

On a related note, I was hoping that the macOS Shortcuts app might have built-in actions to change the Sound Output, but as of Ventura 13.1 Beta 1, it does not. :slightly_frowning_face:

That AppleScript might fail, but the Open a System Preference Pane action can open the Sound preference pane.

Whether that helps any, I don't know.

1 Like

Thanks for the heads up, @peternlewis. Since my comment above I had found a way to open the Sound System Setting in Ventura, but if Open a System Preference Pane works on all versions of macOS, that’s far superior. I will check it out.

Next challenge: Ventura AppleScript UI scripting. :hot_face:

2 Likes

I have a working sound control panel for Ventura. I just want to do some more QA on it before I release it. It only works for Ventura, of course. It was a true pain in the ass to get this one done. Look for it in the next couple of days, but it works on my Intel iMac and my MacBook Pro M1.

2 Likes

I created "Set input and output sound devices in MacOS Ventura" as you requested.

1 Like

I've updated the OP with Version 4.0 of Set Sound Output:

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

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

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

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

Why do you need to open the system settings sound pane in a loop? When I run it once, it just selects the sound pane.

1 Like

@ikenassi, good question!

This is a general practice I use because it makes such steps more robust and the wait can be minimized. (I take a similar approach when a sequence of actions that depend on an application being in the foreground.)

Bottomline: it never hurts and sometimes helps.

Good idea. Better than dealing with variable delays.

1 Like

By the way, here’s a little script to convert the OS version from (potentially) i.j.k to i.j so you can use numeric comparisons.

Set OS Version.kmmacros (3.96 KB)

1 Like

Thanks, @ikenassi. Yes, I've seen a few techniques on the forum. In Set Sound Output, I use:

Keyboard Maestro Export

Please ignore my poorly named local variable. :face_with_open_eyes_and_hand_over_mouth:

1 Like