KM Interaction with a widget (Soundsource)?

Any input on this would be welcomed.
You do NOT need to be running Soundsource to answer my questions..

1: I am using Soundsource from RogueAmoeba.
2: Soundsource does not appear when you use CMD+TAB to switch programs, so is this a widget or something else??
3: As a widget, it does not have its own menu bar, so the option of using the KM action
If menu bar dropdown item xxxx has a checkmark do yyyy else do zzzz is not available
4: It does have its own icon which sits in the standard menu bar.
4a: Left click on icon Brings up a Soundsource control panel
4b: Right click on icon brings up a number of relevant and useful shortcuts

5: What is the best way for KM to interact with soundsource?

Based on that description, I'd probably call it a background application/utility. As for interacting with menu bar icons, I still use Bartender (there are open source alternatives though I don't know how feature-rich they may or may not be by comparison), which allows me to assign hotkeys to interact with any given menu bar icon via either left or right click. Without such a third-party utility though, the only thing I can think of is using Found Image to click on the icon. I thought maybe the native Move focus to the menu bar might be useful, but that seems wholly restricted to the menu half of the bar. Perhaps it might be scriptable either with AppleScript or the command line?

Oh actually a quick search revealed you can set a global hotkey to show SoundSource along with other keyboard shortcuts, which might be helpful.

Since it is a menulet see if this helps you at all.

This script created a new snipped for me in TextExpander at one point. 'Create New Snippet…' menu item:

AppleScript
tell application "System Events" to tell process "TextExpander Helper"

ignoring application responses

click menu bar item 1 of menu bar 1

end ignoring

end tell

do shell script "killall System\\ Events"

delay 0.1

tell application "System Events" to tell process "TextExpander Helper"

click menu item "Create New Snippet…" of menu 1 of menu bar item 1 of menu bar 1

end tell
tell application "System Events" to tell process "TextExpander Helper"

ignoring application responses

click menu bar item 1 of menu bar 1

end ignoring

end tell

do shell script "killall System\\ Events"

delay 0.1

tell application "System Events" to tell process "TextExpander Helper"

try

click menu item "Disable Expansion" of menu 1 of menu bar item 1 of menu bar 1

on error

click menu item "Enable Expansion" of menu 1 of menu bar item 1 of menu bar 1

end try

end tell

I just call SoundSource up using Alfred, but Iā€˜ve just tried my usual Applescript trick for accessing menu bar items, and yes, this works:

tell application "System Events" to tell process "SoundSource"
	click menu bar item 1 of menu bar 2
end tell

1 Like

From the SoundSource manual:

SoundSource is what’s known as a ā€œmenu bar applicationā€.

From that same page:

Finally, SoundSource can be accessed and controlled via the keyboard. When the configurable global keyboard shortcut is pressed, SoundSource’s main window will come forward and receive focus, enabling you to see your current settings, and adjust them.

So if that hot key works when sent from KM, that would seem to be the best method.

Of course, that depends on how you want to interact with SoundSource. It may be that you can do everything you want without even popping its window. Take a look at the Shortcuts actions available -- perhaps you can write a Shortcut to do what you want, and run the Shortcut from KM?

Yes, @hemicyon pointed out the hot key method above, but whether that is the best solution (or the better of the two definite solutions!) is debatable. Assigning a hot key means another hot key assignment to keep track of. My preference would be to use the script. That is, if I needed a solution within KM; I wonder (just a little) how Alfred readily handles this.

Speaking of which, I wonder whether the question ā€œWhat is the best way for KM to interact with SoundSource?ā€ is based on an assumption that KM is a necessary part of a solution. If the problem is just that of calling up SoundSource with a hotkey, and integration with a KM macro is not otherwise needed, then the solution is already within SoundSource.

How will OP run the macro? If it's by hot key then it isn't an "extra" HK if they can assign the same to both the macro and SS and "pass-through by action" works... It's that last bit that worries me, but I don't have SS to test against.

I'm assuming it's a "pop the window so KM can manipulate the UI" scenario -- which is why I wonder if what's needed can be done via Shortcuts (maybe themselves run from KM).

SoundSource does support a good number of actions via Shortcuts:
image

1 Like

Thanks to all who posted. Some things I already knew, and some I did not, but it all helps me progress this mini-project.

PS the obvious route is to use Apple shortcuts, but that seems like blasphemy within a KM environment.

No more than using an AppleScript action, a shell script, or JXA...

Surely that's the beauty of KM -- that you can use whatever works and tie it all up with bow inside a KM macro!

1 Like

Yes indeed—horses for courses.

For a little while now I have been using KM to call Shortcuts.app er, shortcuts to tell SoundSource to redirect the output of Music.app according to another application being launched or quit—whereas for simply calling up SoundSource, I mentioned different methods above. It all depends on what exactly one is aiming to do… and of course the external control methods that software developers have chosen to implement.

That said, if I had the straight choice of a solution in KM or in Shortcuts.app (or, come to that, other applications), I would choose KM. It feels the most like home!

I very much agree!

1 Like