Monitoring for Menu Changes in an App

Does anyone know if it's possible to "watch" a boolean menu item in an application for changes (ticked or not ticked)? Thank you.

Sure. But because macOS doesn't "notify" apps of changes, it means you have to "poll" the value of the flag. So what I usually do is create a macro that is triggered once per second and it determines whether the menu item is checked or not, and saves the result in a global variable. KM supports this by its condition options. For example, create an IF action in your macro and then create a condition in that action by choosing "Menu Condition". This will allow you to specify the name of your Menu item and then you can set a variable to "1" for checked or "0" for unchecked.

But since you haven't named the app you are using this on, there may be other issues that I can't advise you about. E.g., I've heard of some apps that don't update the checkmark until you use your mouse to display the menu. If that's how your app operates, you may have problems with this approach. But most likely it will work. Feel free to try. If you get stuck, I can create the action for you, but then you would have to tell me the name of the menu item (and any submenu names, if any.)

1 Like

You rock, dude!

Sounds like polling might be the way forward for you, but I'd be remiss not to ask the circumstances under which the menu changes, as polling (like using found images) is usually considered the final resort.

I'm unclear - are you asking me a question? :grinning:

Yes. :joy:

Can you give some context as to why you're checking for the status of a menu item? What causes its status to change and why are you checking for it? What is the ultimate goal of your macro?

1 Like

Oh, sure - thanks. I've created a GUI interface for a third party app (inside a WebKit window). When the user chooses a menu item in the app, I'd like to indicate the new setting in my GUI.

A chronic job that checks every minute would be fine…the interface in KM is a little specific, though—like, I'm not interested in specifying the day of the week or time range. I just a want a one minute chron that I can start and stop, lol.

1 Like

I suspect you meant a cron job, not a chronic job. Took me a while to realize that.

KM can do 1 minute macro triggers easily. Don't be confused by the day of week buttons. Just leave them all blue and set the time from 12AM to 12AM. I do this all the time, so I know it works.

P.S. Perhaps we should use the correct words, it's "a macro that gets triggered every minute". It's not "a cron job." Cron jobs are unix processes that are triggered by time. KM also has a "cron trigger" but I'm not sure if that's actually hooked into the macOS cron utility or not. I don't use it since the periodic trigger in KM is pretty much the same thing.

The harder part is that you said you wanted the same macro to be triggered when the user chooses a menu item in the app. I don't believe KM can trigger on that, which is why I said earlier you should trigger a macro to check this every 1 second. I mean, if you could trigger on when the user clicks the menu item, what would be the purpose of a timer trigger? It wouldn't add any value.

Anyway, you marked this as "Solved", but here's a screenshot of the code I was talking about. You would have to replace "Notes" with your own app's name and "MyMenu" with your own Menu name.


Can't it be both? :tada:

1 Like

You a great human being - thank you.

1 Like