MACRO: Set Sound Output, v7.1

Maybe -- and remember that the "Sound" menu bar icon needs to be visible for the AppleScript to be able to target it.

You could, of course, use the AS that targets Bartender and opens the menu to show the options and then select the appropriate one via System Events. But -- again -- without a screen shot of the open menu we can't be much more help.

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

  • If the System Preferences (or System Settings) is already open to a pane, the macro returns to that pane.

  • Updated the TESTED WITH information.

1 Like

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

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

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

1 Like

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

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

  • For the created calling macros, the method used to update the macro icon has been made more robust.

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

  • If the Sound pane does not open and properly populate, open the General pane, then open the Sound pane.

  • If AppleScript intially fails, wait 1.0 second and make another attempt.

  • Updated the error message dialog.

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

  • Compatible with Set Sound Input, v1.0 or later. For more information see: Using 'Set Sound Output' and 'Set Sound Input' Together

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

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

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

1 Like

This seems to have stopped working. I wonder if it was broken by a recent update to Mac OS? Worked for me before.

Hi, @82Taylor. Thanks for the feedback.

Just a few hours before your message I discovered this issue and during the troubleshooting discovered that with macOS Sonoma, Apple has again changed the System Settings with respect to AppleScript Automating the User Interface (a.k.a., Graphic User Interface (GUI) Scripting).

The good news is that I have worked out the necessary changes and upgraded the macro. I will test it thoroughly and, if all goes well, release it this weekend.

@82Taylor, have you also upgraded to macOS Sonoma?

1 Like

Hi @_jims!

I have updated to Sonoma.

Thank you for being so responsive! Amazing

1 Like

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

  • Support for macOS 14 (Sonoma): new AppleScript UI script compatible with Sonoma (slightly different than Ventura).

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

1 Like

I've had this working pre Sonoma but for some reason I cannot get it to function this time. New device. I've triple checked my setting and names of devices.

I've even installed it as the first macro. The correct area is opened in System Settings. In past versions even when it was unable to determine the correct output I would see movements in the output pane. I no longer see this. Would that still occur? I'm wondering if something has changed yet again with macOS?

To me it's as if the script is not tabbing over to the output area. I say that because I can hit tab and the selection moves from the Sound selection in the sidebar to the output area with the Macs built in output selected. If anyone has any ideas I'm open to suggestions.

Notes:
MacOS 14.1.1
KM has been restarted after granting permissions. Including Automation.
Desired localization English is set to bottom position.
No special characters and the HomePod is named Office. I have tried with other HomePods too.

Hi, @OneEyedJack. Sorry you are having a problem with your new device. Please try these steps:

  1. Delete all copies of the macro Set Sound Output that you currently have installed. Also, delete any calling macros that you may have created.

  2. Download and install: Set Sound Output

  3. From the Keyboard Maestro Editor, use the Run button to launch the macro Set Sound Output. You should see this dialog.

  1. Enter the name of your sound device. Leave Call As a Subroutine selected.

  2. Repeat Steps 3 and 4 for each of your sound output devices.

After you complete these steps, try running each of the newly created calling macros. Then please report back.

Hey @_jims

  1. Check.
  2. Check.
  3. Check. Yes.
  4. Check.
  5. Check.
  • I get a KM notification about searching output for the devices name. Then the failure message.

Can you list all the permissions areas that might need to be granted inside macOS if any beyond KM? Perhaps I missed one? I don't think so. I'm pretty good at getting those all configured.

Is there any way I can capture logs for you?

Notes:
I upgraded to the macOS 14.2 beta 3. My phone is on beta 3. No reason not to try the macOS beta. No change. Additional Mac running 14.1.1 continues to be available.
I'm also using Keyboard Maestro 11.0.1

Does the macro run successfully on the additional Mac?

On the troublesome Mac:

  1. Open the System Settings and open the Sound pane.

  2. Click the Input selector (right side).

  3. Run one of your calling macros.

Report back the results:

  • Does the macro select the Output (left side)?
  • Does do see the output device of interest? If so, was the output device there as soon the macro selected Output?
  • Does the macro select your output device?

If it's still not working please supply a screenshot of the Sound pane with the Output (left side) visible.

Morning,

I started getting a notification this morning about an item being out of range on the MBP. This is during the initial creation. I'm not sure why I did not earlier, I started from scratch again on this device a few momnets ago. So maybe it had something to do with it. Interestingly, I did not get the notification on the Studio or the MBA. I'll go back and double check that. I'm away from those Macs at the moment.

All of my Mac's are affected by this.

3 - 1 Studio M1 (14.1.1), 1, MBP M1 (14.1.1), 1 MBA, M2 (14.2 beta)

CleanShot 2023-11-17 at 06.54.53@2x

This is how the System Settings looks when the failure occurs (MBP). This is exactly how the focus appears. I've not changed anything to be in or out of focus.

Q's:

  1. Yes
  2. Yes, Yes.
  3. No.

@OneEyedJack, I'm going to send you a DM.


In the meantime, is there anyone with an Mx processor that is successfully using Version 7.0 of this macro with Sonoma? If so, please reply here. Thank you!

1 Like

This used to work for me but now that I am on Sonoma on Apple Silicon (M2), it does not. I have found no way to programmatically set an Airplay destination on macOS.

Hi, @BobM, thanks for reporting issue. It's interesting as I now have a MacBook Pro with M1 Max chip and the macro continues to work as expected for me.

Maybe this issue could be addressed with some focused testing. If you (and/or @OneEyedJack) have some time I'd be willing to work via DM's and send test versions of the macro. I'll have some time for troubleshooting this weekend.

1 Like

Sure thing. Just let me know.

1 Like

same here

1 Like