Interact with a menu bar item with keyboard maestro

Hi there,

I have a application I am using called ‘Barrier’ to connect my mac to my PC. I would like to have this application toggle whenever I dock my laptop (I have managed to create a trigger with bash to detect whether I have connected my ethernet cable or not.) The main issue is that I can’t just activate the app and use a keyboard shortcut as the app when it’s open doesn’t actually have any shortcuts. BUT, the menu bar app? (I’m not sure that’s what you call it.) does have keyboard shortcuts when you click on it. I just cannot figure out how to activate the menu bar app using keyboard maestro. Can anyone help me? Is there a better way to do this that I am not thinking about?


One way would be to use Keyboard Maestro’s click on a found image step.

1 Like

Thanks, this should work well. Any idea on what to do if the icon isn’t on the menu? Is there like a ‘look for image’ condition? I can’t find it.

Just tested it, it works great. Thank you!

Check the action result token from the step.

Yep. Everything works, thanks! I’m still new to automation on the Mac, this is my first mac in a few years.

Upon futher use, this solution actually doesn’t work due to the funky way barrier deals with mouse inputs. Any other ideas would be welcome. I think I might get it to work by getting Maestro to activate f3 and then deactivate f3 to get the mouse to show.

Bartender 4 can assign a keyboard shortcut to menu bar items.

Bartender 4 Gets Menu Bar Automation — MacSparky

Hi @CaptainObi, here is an AppleScript that I use over Keyboard Maestro:

(1) Please enter the correct app name here. I always determine this via the activity display.

(2) From here on, menu items are called up in the popup window.

(3) With this you determine which menu command should be executed.

 tell application "System Events"
	tell application process "Barriere"
		tell menu bar 2
			tell menu bar item 1
					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 3 times
		key code 125
	end repeat
	key code 36
end tell

Here is an example of this:


If you use the Bartender app, the AppleScript is executed in the background.


Thank you! This is exactly what I needed. I’ll try this out.

1 Like