"Select or Show a Menu Item" in top bar menu app?

Can’t find and figure out how to create a shortcut to activate and/or to select a menu item in an app.

The app is located in the top menu bar only.


1 Like

The only way I’ve figured out how to do this, is having KM look for and click the icon of the app using the Move or Click Mouse action. When the app icon is click, I have KM tab down to the menu item.

Maybe if the app is AppleScriptable, it could be activated that way.

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.

1 Like

I don't suppose there are any new revelations since this was last visited. I am trying to click an animated status bar item that reflects ping times... so the item will toggle between "102ms" and "Failed" and "140ms" or some other time.

...What I am really trying to do is bring up the menu under those items.

So "ms" or Failed are always displayed. I have tried to image select on these, but have yet to be successful even though the KM IF STATEMENT reports the image is recognized, I cannot seem to get the mouse to select. I am aware that with the image selection, you cannot have the image present anywhere else on the screen (like in the KM macro editor, etc.).

The bar looks like this.

I have two instances of the program and do not care which one I access, because by default, once I know where one is, I will know where the other is located.

If anyone is interested in AutoPing, it can be found here (it's free).

On a related note, Is there a way to simply run periodic ping routines within KM and place the results as two constantly updating numbers (say a ping every 5 seconds to each server) as two numbers in the status bar? If you look at my image, I am pinging two separate servers (specifically Baidu.com and Google.com), which I find very useful when working with VPNs from within China.

I find that running AutoPing takes up very little resources, which would be necessary for any script / application that I would have on 100% of the time for monitoring purposes.

Hey Ed,

AppleScript to the rescue.

Since you have two instances of the app running there may be issues with the name. Have you renamed one to get the 2nd instance to run?

# Open Autoping Menulet
tell application "System Events"
  tell application process "autoping"
    tell menu bar 1
      tell menu bar item 1
        perform action "AXPress"
      end tell
    end tell
  end tell
end tell

I didn't have any problem using a found image to click the menu, and I think I was able to make it unique enough not to have false-positives.

I like the idea of that Autoping, but it's not a well written app – nor has it been updated since 2013.

I tried to throttle it down to 1 ping every 2 seconds, but it doesn't work reliably.

Unfortunately I don't find any obviously good alternative on the app-store.

Is there a way to simply run periodic ping routines within KM and place the results as two constantly updating numbers (say a ping every 5 seconds to each server) as two numbers in the status bar?[/quote]

No. Keyboard Maestro cannot display anything in the menu bar.

The best you could do is fire off a notification or open a text window if there was an issue.

On the other hand you could script the Terminal, or you could write the ping output to a log file.

There are all kinds of ways to handle this task, but no way to display the result as conveniently as Autoping.


Another app which could do this would be Textbar ( http://www.richsomerfield.com/apps/ ).

You can script your own items for the menubar.

1 Like

If you can use the information on the desktop, then you could use GeekTool.

( http://projects.tynsoe.org/en/geektool/ ) or Übersicht ( http://tracesof.net/uebersicht/ )

1 Like

Ok, Jimmy, for my particular problem here, Textbar looks ideal. I already having it pinging against Google and Baidu at the timed interval of my choosing. Very nice.

If you (or anyone else can assist, I am no expert when it comes to command line scripting. The current script I am using is

ping -c 1 google.com | awk -F" |=" '/time/{print $10"ms"}'
ping -c 1 baidu.com | awk -F" |=" '/time/{print $10"ms"}'

The problem is that the format comes out as the following graphic.

I do not want microseconds, simply the 502 and 288 numbers for Baidu and Google, respectively. In fact, I simply want two numbers presented on the bar (e.g., 502 288). No need for ms either.

I know this is not really KM at this point, so my apologies for that. But if anyone can quickly guide me to simply printing those (i.e., removing the numbers after the decimal places, I would appreciate it.

This should remove the “ms”

ping -c 1 baidu.com | awk -F" |=" '/time/{print $10}'

In regards to the decimal, then I can not help.

Thanks Jimmy - yes, I got that one figured out, I even removed one decimal place (still have two) by putting a dot after the F. I also removed the icon. So I’m getting there. I really would like to have the digits fixed at 4 digits each.

Hey Ed,

I’m not sure what you mean by fixed 4 digits.

Since you’re dealing dealing with milliseconds I’d think the non-decimal portion would be sufficient.

In any case this is an easy one.

ping -c 1 baidu.com | sed -En '/time=/{s!^.+time=([0-9]+)\..+!\1!;p;}'


Many Thanks Chris. The 4 digit placement is to facilitate displaying ms through seconds (e.g., 0001 through 9.9 seconds … i.e., 9998) (a few seconds happens often in China).

I do not care if the leading zeros are displayed, but I care that they are held in place so that the spacing taken up on the bar is fixed.

There is one other problem, that of varying space taken up on the status bar. It happens because the numbers presented are not fixed in position. This results when there is no return ping (i.e., Failed). In this case, if the program defaulted to just 4 blank spaces or 9999, then it would avoid the shifting. Right now the program simply displays a dot that takes up a single space.

EDIT: The 3 digit is a big improvement.

Hey Ed,

This will give you 4 digits and handles a null return.

myPing=$(ping -c 1 google.com | sed -En '/time=/{s!^.+time=([0-9]*)\..+!\1!;p;}');
if [ "$myPing" == "" ]; then
	printf -v myPing "%04d" "0";
	printf -v myPing "%04d" $myPing;
echo $myPing;

See how that works.

If you have problems try to post a sample of the raw data returned from the ping.


And that, my friends, is the way that is done. Many Thanks Chris.

Perfect. I set the intervals to 3 seconds per ping. I could add more servers if I was so inclined. And when there is no internet, everything goes to 0000 0000.

Hello kamil, since my English is not so good, I have times made a video, as I have solved your question :slight_smile: