Unfortunately, I just get "System Events got an error: Can’t get menu bar item 1 of menu bar 1 of process "SystemUIServer" whose description contains "volume". Invalid index."
I don't know enough AppleScript to be able to work around this. Trying to find AppleScript documentation using search engines just returns a load of articles that never seem to quite tell you what you need…
Things change. Without an OS version we won't know how to target the Sound menu bar icon.
For instance -- in Ventura (and maybe before) "Sound" was moved into Control Center's purview. So (assuming "Sound" is in the menu bar!) you should be able to simulated-click it with
tell application "System Events"
tell process "ControlCenter"
set theMenu to item 1 of (get every menu bar item of menu bar 1 whose accessibility description is "Sound")
click theMenu
end tell
end tell
And things are particular to devices. Without a screen shot of the choices you have it'll be difficult to target the right one.
Post the info required and (hopefully!) something can be sorted.
Cooked the graphics on my Mojave iMac at the weekend -- but VNC to the rescue!
tell application "System Events"
tell process "SystemUIServer"
set theMenu to item 1 of (get every menu bar item of menu bar 1 whose description starts with "volume")
click theMenu
end tell
end tell
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.
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 MacroWith 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.
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.
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.
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.
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).
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.
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
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.
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.