Menulet Apps

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?

You can adress that menu item with this:

tell application "System Events"
    tell application process "bzbmenu"
        tell menu bar 1
            tell menu bar item 1
                perform action "AXPress"
            end tell
        end tell
        repeat 2 times
            key code 125 -- Down Arrow
        end repeat
        key code 36 -- Return
    end tell
end tell

Thanks for the script @Tom :+1: I will also install it for myself.

1 Like

Forget my old script from above. This one runs faster:

tell application "System Events"
    tell application process "bzbmenu"
        tell menu bar 1
            tell menu bar item 1
                try
                    with timeout of 0.1 seconds
                        perform action "AXPress"
                    end timeout
                end try
            end tell
        end tell
    end tell
end tell
do shell script "killall 'System Events'"
tell application "System Events"
    repeat 2 times
        key code 125
    end repeat
    key code 36
end tell

It’s an ugly hack to bypass the strange delay (OS bug?) as already mentioned here.

If you don’t see any delay with my previous script then… use the previous script.

1 Like