How to Access the Top Menu (Apple Menu) Bar?

I'm trying to create a macro to change f.lux but I can't use "image search" because the f.lux menu is semitransparent, so anytime the background window changes, the macro doesn't work. Any idea how to press the "Preferences..." item programmatically?

I use the app “Bartender 2”. Here is a short video. At Intresse, I can give you the macro.

Please select the date or the clock in the menu bar. The background remains the same. Then use the left arrow on flux. Use the down arrow key to go to your menu command.

Here is my macro. Just change it for yourself.

Start : Stop copy.kmmacros (7,4 KB)

Rather than duplicating all those "Left Arrows", how about using the "Repeat" action, like this:

By the way, the "12" is an estimate. I'm not really sure how many you have in your macro. I can't count higher than 3. :slight_smile:

Thanks for the tip @DanThomas. I have only been here for a few months and I am grateful for any improvement. I can spare a lot of work with it :+1:

You’re welcome. We all learn as we go. That’s one of the reasons I try to at least skim all the posts - you never know what you’ll learn!

Glad to help. :slight_smile:

1 Like

Have you seen the topic about accessing menulets?

In particular my post about the f.lux menu:

This will/should do it:

_Flux Menu - Preferences.kmmacros (2.3 KB)


###Notes:

  • The whole stuff with “timeout” and “killall System Events” was necessary because of a strange delay caused by the first AXPress. I didn’t find a better way to work around it. Credits to Aviral Bansal for the ‘killall’ idea.

  • In case you modify the script, attention with the ellipsis in “Preferences...”: these are three separate dots, not the ellipsis character.

  • If it doesn’t work set the timeout to 0.2 or 0.3, etc.

Edit (2017-01-19):

I have posted a more complete standalone version of the script over at the f.lux forum.

Thanks for sharing this tip, @Tom. I think your technique may be helpful in dealing with similar issues trying to control the UI of KM Status Menu.

Instead of the combination of “try” and “timeout” you could also use “ignoring application results”, but this worked for me only in a standalone script (launched from SD or FastScripts), but not via KM.

Again many many thanks for the tip @DanThomas. I have modified all my macros accordingly :+1:

1 Like

It shouldn’t be a problem. This works for me on my macOS 10.12.2 system.

With this sort of brute-force approach timing issues are likely, and it may be necessary to use pauses appropriately to let the UI catch up to Keyboard Maestro.

Flux ⇢ Disable for an Hour.kmmacros (6.0 KB)

This is very acceptably quick on my machine.

NOTE: People should complain in droves to the developer of Flux and to Apple about the poor/buggy support for accessibility.

-Chris

Nope. Weird. I tried your macro and it’s the same as with my macro above: It works only with the try & timeout in the AppleScript:

tell application "System Events"
  tell application process "Flux"
    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

The “ignoring” version does not open the menu. (But it does when launched from SD.)
KM 7.3.1 and OS 10.12.3 Beta (16D30a) here.

Maybe the 10.12.3 makes the difference, but I don’t really believe. Maybe some differences in KM’s settings?

Hmm… More likely the former than the latter.

Your script above works fine here too, although I’ve reduced the timeout to 0.001 seconds.

-Chris

Reducing the timeout to anything below 0.1 instant-crashes my ScriptDebugger (6.0.3 (6A191)).

Edit: Doing so in KM does not crash, but it brings back the 5s-delay. The lowest I can go on my machine is 0.02 seconds.

Hey Tom,

That doesn’t happen in Script Debugger 5.x. I’ve reported this to Mark via the crash-reporter.

Curious…

-Chris

Finally a reason to get a new and faster Mac :grinning:

Hey, I have found it!

System Events was unchecked in the Accessibility Privacy settings:

Now also in KM both methods work. I have no clue why and since when it was unchecked. And the weird thing is that all of my other UI scripts were working, and that it affected the “ignoring application responses” only when launched from KM.

Hey Tom,

Very odd – good job finding the problem!

-Chris

Hey Tom,

I would like to experiment with this shell script "killall System\ Events" but i can't find the script itself nowhere. Maybe i am overlooking something obvious, but i guess i have to install it in /usr/local/bin/, right?