Menulet Apps

Hi

I'm stumped on getting two of my macros to work as intended. i will put them in separate threads

The first is:

I'm trying to create a macro so I can assign a shortcut to access a Menulet app and then choose the very first option. This option then opens a dialog where I click the "connect" button.

I've tried using record and then adding in pauses but it hasn't worked. Also, the shortcut command that is built into the app does not work.

Was hoping someone here would have some hints.

Thanks in advance,
Richard

Selecting status menu items is difficult primarily because there is no easy way of specifying them - they don’t have names so its hard to identify them.

You can use a Click at Found Image, although even that can be difficult as they often animate or change icons based on various states. If the icon does not animate or change state (or has a known state when you want to select from it), then this can be a good solution, followed by Insert Text by Typing “Menu Name%Return%”

To click relative to an image, you use the Mouse Click action, configure it to be relative to a found image, and take a screenshot of the desired area of the screen using Command-Control-Shift-4, and paste it into the image well on the action. The image has to be unique (which includes not being visible in the action if the image is small enough not to be shrunk in the image well) otherwise Keyboard Maestro will not know where to click. The Display option in the action will allow you to see where Keyboard Maestro is matching.

I have looked into it on multiple occasions, and will no doubt look in to it again, but its a difficult problem.

2 Likes

Hey Richard,

Rule-of-the-thumb – always tell us what software you’re using. It saves time and makes it more likely you’ll get help.

Since Bluetooth MIDI Connect is a free app, I downloaded it from the app-store and took a look.

It’s dead simple to open the menulet using an Execute an AppleScript action to run this script:

ignoring application responses
   tell application "System Events"
      tell application process "Bluetooth MIDI Connect"
         tell menu bar 1
            tell menu bar item 1
               perform action "AXPress"
            end tell
         end tell
      end tell
   end tell
end ignoring

But – once the menu is open there’s a 6 second delay, before you can operate on the menu items with System Events. (Something’s buggy there…)

So – use the Execute an AppleScript action and then a couple of Type a Keystroke actions from Keyboard Maestro to perform down-arrow and return keystrokes.

NOTE: The menulet I downloaded did NOT have any keyboard shortcuts – nor does it have the capability of assigning them. I conjecture that the keyboard shortcut you see in yours was assigned using the system keyboard preferences. Sometimes these don’t work properly – sometimes they work if you change the keyboard shortcut – sometimes they work if you quit and restart the app.

-Chris

2 Likes

Chris, I love it when you use clauses like this. :wink:
I always append "for Chris". LOL

For most of us, not only is stuff like this not "dead simple", it's not simple at all.

Just a thought for others, so they don't think they are "stupid" for not knowing how to do this. LOL

Actually, that same delay exists when opening the KM Status menu by AppleScript, and even when using the KM Action "Show Status Menu".

2 Likes

Awesome. Can’t wait to try it out. Thank you so much.

What a great forum. Everyone has been so helpful!!

Works great!

This problem is so frequent that I'm going to ask for more details.

Important, because no easy way within KM to do it. If AppleScript will work, that would be valuable for many KM users. But it didn't work for me.

1.) I don't know AppleScript and don't want to learn. But am willing to buy an app like "Bartender" or "ShortCat" for this. Do those apps play nicely with KM? Or is AppleScript the only reliable way to access the top right corner of the screen?

2.) In the AppleScript routine above, what means, "AXPress"? Should that be changed for each, different menulet? If so, what are the options for that variable.

3.) In example below, when I used "Try" button in KM Editor, nothing happened. (Other than KM's fingers wiggled for 1/2 a second.) (I opened f.lux with a mouse click for this screen pic.)

Please make answers "dead simple".

I thank you. Many other KM users, with this same problem, will thank you, too.
.
.
,

.
Looks like software “Bartender” has solved this problem.

Using status menu items (right side of menu bar) takes endless mousing around.
So, now I’m looking at “Bartender” – on trial.

Works fine, but interface is a jumble of preferences.
I’m spoiled by the clean, straight-forward, interface of KM.
I don’t want to buy “Bartender” … much prefer to stay within KM.

If KM solves this problem, I suggest offering a “KM-Pro” edition with that feature, for a premium price.
How much premium?
Double the current price; I’d buy immediately.

For anyone who wants to look at "Bartender, there’s a free trial at:
Macbartender.com

The process name is “Flux” (not “f.lux”). This script will open the f.lux menu:

tell application "System Events"
  tell application process "Flux"
    tell menu bar 1
      tell menu bar item 1
        perform action "AXPress"
      end tell
    end tell
  end tell
end tell

Tom -

That works for f.lux.
Thank you for responding.

Now, the more important question:
How do you know the names of process?
If there is an easy and direct way to know those names, then many users of KM can use the script you provided.

For example:
To open menu bar item, "Network Preferences," with drop down menu, what is the name of that process, and how do you know it?

In "Activity Monitor" I found "Network Preferences".
But plugging that into the script does not work.
Screen print below:

Top half shows Network Preferences, which I opened by clicking.
Bottom half shows the script used in KM.
But this script does not open Network Preferences' drop down menu.

What is the best way to find correct names of processes?

Or, perhaps your answer will be, "learn Apple Script". :confounded:

In general the Activity Monitor gives you the process name. However I don’t have the Networks Preferences menulet as shown in your screenshot, so I can’t say much in that particular case.

With the System’s menulets the process name is a bit different. I can for example open the Wi-Fi menulet with this:

tell application "System Events"
  tell application process "SystemUIServer"
    tell menu bar 1
      tell (first menu bar item whose description starts with "wi-fi")
        perform action "AXPress"
      end tell
    end tell
  end tell
end tell

So, you could try to replace “wi-fi” here with “network”.

Keep in mind that certain System Preferences (for example Network Preferences!) are directly scriptable. That means you can do things without clunky UI scripting. You find the scriptable System Preferences and examples here.

.
Thank you, Tom, for patient explanations on this topic.

Looks like the only way to do this – within KM – is learn Apple Script.

My decision:
I will mouse click, or buy the utility, “Bartender” to handle this problem.

No. Assuming that your network menulet is the system’s standard menulet, it’s pretty simple:

  1. Run this KM macro: Get Descriptions of System Menu Bar Extras.kmmacros (1.6 KB)
  • It does this:

  • It will output the descriptions of all enabled system menulets. For example:
    Notification Center, Siri, time machine, system sound volume, AppleScript, bluetooth, text input, Clock, Wi-Fi, four of four bars, ….

  1. In the output look for a description that is likely to be the one of the Network menulet. In my case it’s Wi-Fi, four of four bars, in your case it’s probably different and may be something like Ethernet… or Connected… etc.

  2. Then just paste the description (or the first part of the description) into the AppleScript from the post above.
    Like this (the red part is where the correct description goes):

[…]
tell (first menu bar item whose description starts with "<description here>")
[…]
1 Like

.

[quote="peternlewis, post:2, topic:4988, full:true"] ... use a Click at Found Image, although even that can be difficult as they often animate or change icons based on various states.
[/quote]

Thank you, Peter.
Now I have started using "Click at Found Image" to access Menulet Apps.
It works very well.

Solves 90% of this problem quickly and easily, entirely within KM, without any AppleScripting.
Besides the Finder menu bar, it also works within applications, such as Firefox.

The 10% remaining -- with changing icons -- can mouse and click.
I'm content with that.

So no need for a utility like "Bartender" to access menu bar items.

I'd never used "Click at Found Image" function before, so was unsure where to start.
To help others get started, here is an example that works.
(This example opens Firefox add-on, "SiteDelta".)

Fine if you’re content with the “Click at Found Image” approach. But keep in mind, the AppleScript solution is…

  • by far less CPU-expensive
  • more reliable
  • proper (the Found Image thing always is a last recourse)

You don’t have to learn AppleScript to apply it :wink:

@Tom, thanks for sharing.

Apparently many menulets are NOT standard. Your script misses many of mine:

It only displays the enabled menulets. As mentioned here.

Menulets like the Network one are tricky because the description changes in function of what is displayed. Another approach is getting them by item number. But this isn’t fix either.

I too am attempting to select a menu item from a menulet app, but I'm having trouble getting it to work using the advice in this thread.

In my case, the menu I'm trying to access is for Backblaze (the menu appears to be named 'bzbmenu' based on what I see in Activity viewer). I want to select the item 'Backup Now'.

I was able to get it to work using Found Image, but I can't use this method because I want the script to trigger at a time when my display will be asleep (but not my computer).

I tried using this applescript:

tell application "System Events"
   tell application process "bzbmenu"
      tell menu bar 1
         tell menu bar item 1
            perform action "AXPress"
         end tell
      end tell
   end tell
end tell

Running this did open the menu, but did not select an item from the menu. (The menu item I want to select is 'Backup Now'.) It just opened the menu and a few seconds later the output 'missing value'.

I have my menulets organized using Bartender if that makes a difference.

Any ideas how I can accomplish this?

Thanks, but I don’t understand. What is the macro?