Yes I've utilised the keyboard shortcuts but stumble around the keyboard in practice. I want to create automations that would ease the process, such as bringing the menu forward, selecting an app's volume and toggling its effects mute button, say four hotkeys in a row. I've answered your question with another user's ion the comment above. Display current audio output in menu bar? - #20 by stujumpsrope
Yes, OCR is not an effective way to return a precise location, even though I did manage to write a macro called MoveMouseToWord which shows it's possible, and you can look for it if you want. But in this case I think there may be better solutions.
Yes, this will be a tricky problem to solve, but I have some ideas.
METHOD 1
The first thing I noticed that might help you is that when you click on the menu symbol (or press a key) the menu symbol itself changes to a darker colour. This is the first thing I would try. I would use a Find Image action, either in a loop or in a loop with a 0.3 second Pause or in a periodic 1-second trigger. (Either method is okay for testing purposes.) When the symbol changes colour, you know the app has been activated. I can't tell if the menu symbol changes when the menu is pinned to the desktop, because you didn't show that (this would be helpful to know.) (See METHOD 2 below for more info.)
The second thing I noticed is that the lower left of the window does have a good coloured image that can easily be used to locate the bottom left location of the window, regardless of whether the window is pinned or not. This can be very helpful to solve your problem, but you would only be using this if the window is visible, based on the "first thing" I mentioned above.
The third thing I noticed is that the upper right of the window also has a coloured image that will probably work for detecting the location of the upper right corner of the window.
One thing you didn't say, which could be important, is what happens if you close a pinned window. If you re-open the app after closing it in pinned window form, does it return as a pinned window or as an unpinned window?
I can help write a template macro that will help you with this, but you will have to write it yourself because I don't have your app and it will be an image-dependent macro.
One small tip that may help with this. You could make your image search more reliable if you changed your screen background to a solid colour instead of the rainbow effect. This could help in many cases, although not on every case.
METHOD 2
You may prefer to avoid using Find Image to locate the app. That's fine. You could probably hook into the user's shortcut keys to detect when the app is activated. However for practice with Find Image, I recommend that you try my first approach, above.
METHODS 3a, 3b and 3c
It's possible that there may be a difference in the output of the command "ps -ax" when SoundSource is visible on the screen vs when it is not. in fact, I've even seen a case when the IF action with the Application trigger could detect if an app was running even though the app didn't have a window. This would probably be the best way to poll, if it works, but you will have to test if that works. If it does work, it may also work as an Application Launch trigger, which would be even better.
Overall, I think this task is quite doable. I know I didn't address the issue of targeting specific volume levers yet, but that should be doable if this first part is doable.
BIG TANGENT
I see that your goal seems to be to change the audio volume to specific volumes for specific apps. I already solved this problem with my own macro, which doesn't require SoundSource (but my macro only works when the apps are the front app of the GUI, not generating sound in the background.) If you want to consider my solution, you can look here:
I don't mind if you reject all my ideas. I just enjoy helping people, and writing this post helps me to wake up and get going.
Back to the original topic here, I realized SoundSource has a Shortcut to get the output device. Can I show this output in the KM Status Menu?
AFAIK, the only things you can show in the Status Menu beyond what KM includes are enabled macros. So you're back to using the previously-posted macro that enables/disables macros depending on the output device -- only this time you can trigger that Shortcut from KM and save the result a variable:
Have you tried firing off the keyboard shortcuts with KM, using a macro that uses "Type a Keystroke" actions to drive the menu bar app? My worry is that you'll have trouble targeting it as it isn't a "proper" application, but give it a go.
Shortcuts is very much a first-party app, and Apple's preferred way of scripting apps now. A series of Shortcut actions will be more stable, certainly more reliable, than most other ways of doing this.
Hi @Airy
No it doesn't. that's just the background colour forcing the translucent menubar to make the icons black. Right now they're white because I have a dark background.
Out of curiosity, how would you trigger such a loop? I struggle very hard and my mind gets confused when attempting to trigger program loops.
You can tear off the menu and place it anywhere when itβs pinned; however, if you close it, it will animate back to the menu bar. You must click on the icon for it to open, and it will return unpinned.
Thanks for your tip with high contrast images for OCR. If I'm going to use keyboard shortcuts tin a series to make a button or slider active, this would be the first action, or could be used to pin effects windows when they pop-up. But as there is a built in F8 shortcut to call the window, that would probably be better as the first action.
Could you explain what you mean by this?
If this is more reliable and faster, I would prefer a code-level approach. I use Better Touch Tool where it shows you variables in the UI underneath the mouse cursor to specify where exactly on this screen you want a modification. I don't know what ps-ax is, but I'm guessing it's UI code.
Tangent Macro
I'll have a look at your macro. Yes, that is pretty much what I'm doing in the first place.
More importantly, I'd like to map more efficient keyboard shortcuts to trigger effects on and off and manipulate the volume very quickly, almost simultaneously, like a DJ mixer (I work in radio). If I can get to mapping the sliders to keys for smooth volume control, then we'd be very much scoring goals.
Thanks for you help.
Hi @Nige_S
Yes, as I tried to imply in my question, I've made all sorts of keystrokes to activate the F8 key in KM, as well as a trackpad gesture. This brings the window up immediately, and I can use SoundSource's keyboard shortcuts to navigate. However, it's not intuitive, and I definitely have to automate some keystrokes in quick succession, as well as use the tab key, to get to the switch or slider I want to Toggle. If you're interested I can publish my results.
Thanks for your advice on using Shortcuts. I thought analysing some script in the background to detect that the window is present would be the fastest and most accurate approach, but I'll certainly give it a try.... Using the trackpad to activate a volume slider would be amazing. Do you know if Shortcuts has the ability to do that?
Thank you.
You could use the app OneThing to display info on the menubar. It takes variables and I think has shortcuts integration.
You can probably skip ahead a few paragraphs if you want, because further down you agreed to exclusively rely on a hotkey (F8) to open the window, which means this discussion is now moot.
I don't think I'm clear. Let me re-iterate. Since I can see with my human eye that there's a visible difference in the icon when you click on it, that's what you can use to detect if the user has clicked on it. KM's Find Image action can detect almost any change that the human eye can detect.
If you like to change your screen background from dark to light, then by writing macros carefully, you can still tell when the icon has been pressed, as long as there's a difference in shading or colour. If you can see it, so can KM actions. That's my point.
The question "how do you trigger a loop?" is the wrong question. Loops run continually. So, for example, you can trigger a loop when macOS boots, then let the loop run while macOS runs. And loops can use actions to detect if a conditions is met. This is often called "polling." Polling is different from triggers. Polling is less efficient, but it works. Some people reject polling even before they test how much of a burden it adds to the system. You are free to reject polling, but you shouldn't reject it before you measure how many resources it uses. I use polling all the time, when there's no better solution, and I'm happy with it.
Great news! That means my simple polling approach will work!
Usually my tips regarding high contrast was for Find Image, not OCR. However it may also apply to OCR. I just haven't tested that.
I meant that if you want your KM macro to know when an application is activated, even an app like yours, which does not open a true macOS window, the best way is for KM to intercept the key that you use to open the application, not try to poll an icon on the screen to see when you activated it using the mouse.
Superb! That means we can stop talking about polling, since you have agreed to use F8 to open the window. We can have KM detect that you have pressed F8 in order to activate the window. So let's stop talking about icons, colours, shading, polling and menu bars, since you have agreed to use F8 to open your window.
We can stop talking about polling solutions since you seem to have agreed to use the F8 key to activate the window.
What this means is that you will need to write a KM macro that is triggered when the user presses the F8 hotkey, then your macro will have to open the app (there's more than one way to do this) then your macro can do the things it wants to do, like resize the window and adjust some settings. This is a big win. We can get to this next. But we have made a huge step forward because you agreed (I think) to trigger the window exclusively using a function key, therefore I don't have to help you with a polling solution. We've just solved half the problem.
EDIT: Maybe you didn't mean you wanted the window to be triggered by a hotkey. I'm starting to wonder if you meant something else. Maybe you were talking about how the macro should activate the application. That would be phase II of your solution. I'm still working on phase I, which is determining how the macro detects that the program is activated.
Thanks. Sindre makes some incredibly utilities. But in the end I'm just using the macos Sound menu bar item. It serves the most basic needs until I can hopefully figure out what's causing SoundSource to get all staticky when I have my AirPods in.
Assuming you mean "to adjust the volume slider" -- doesn't look like it. You can get the current level, you can set a new level, so it's easy to "increase volume by 1". You might be able to use a KM gesture trigger to fire that multiple times, but that sounds clunky.
The best way to drag a slider is probably to drag a slider! Maybe look at a macro that uses image detection to put the pointer in the right place, has a "Click and hold" action, pauses until a certain key, eg V
, is released, then finishes with "Release mouse button". You'd trigger it with, say, β₯βV
, keep the V
key pressed, do your trackpad wiggling, then release the V
key to set the new level.