Can't click menu bar icon's menu reliably

I would like to press the F19 key on my keyboard and have it change profile on my stream deck (I can't use a button on the stream deck itself as I need all 32 buttons for this application).

You can do this with a mouse by clicking the stream deck's menu bar icon, and then selecting a profile from the drop-down menu:

Screenshot 2021-01-05 at 09.48.07

But I can't find any way of doing this automatically.

  • I can't use absolute position because menu bar icons might change position
  • I can't use a found image because menu bar icons might look different e.g. in dark mode
  • I can't select it with arrow keys (if I select a menu bar icon then use left and right arrows, it skips over the stream deck icon).
  • I can't find the menu bar icon with UI Browser (possibly something I'm doing wrong here?) so I can't write an AppleScript to click it.

I was wondering if anyone has any other ideas?

Managed to solve this one myself! As this particular image only changes with light/dark mode, I used an If Then Else action to check if dark mode is on and then search for the appropriate image.