Menu Item Availablity?

Hi,

How can we use KM to know if a menu item is available in a particular application.

Lets say how can we know if the menu item 'Expand Action' is available in KM?
I have tried the if statement of menu item and it is returning an awkward answer, please see the image attached (running latest version of KM 7.1.1)

Hey Ali,

What you show does nothing to indicate there is an awkward answer or why there might be.

Please explain. (Edit – Ah, I missed the “(currently maybe)” until Peter pointed it out below.)

The way this action works:

  1. The app in question must be frontmost.
  • Keyboard Maestro poles every menu item of every menu looking for the designated criteria, until it finds it – or fails to find it.

Because of the way this works Keyboard Maestro can take a fairly long time looking for something.

If you want something faster you have to resort to GUI-Scripting with System Events and provide more exact targeting:

tell application "System Events"
  tell application process "Keyboard Maestro"
    tell menu bar 1
      tell menu bar item "Edit"
        tell menu "Edit"
          tell menu item "Insert Action"
            tell menu "Insert Action"
              if menu item "Interface Control" exists then
                return "TRUE"
              end if
            end tell
          end tell
        end tell
      end tell
    end tell
  end tell
end tell

Another benefit of using this method is that the target app need NOT be frontmost.

On my system the script above takes ~ 0.05 seconds to complete the test.

-Chris

It generally will only say “maybe” until the Keyboard Maestro Engine responds to the query as to the result of the conditions.

So when you first create the action, or when it is first displayed, it says “maybe”. And then it asks the engine for the status, and the engine responds with true or false which it displays. And then it asks again every second or so.

Once the engine has responded, it will stay as “(currently true)” (or false) until it gets another response.

So it looks like the Keyboard Maestro Engine is not responding to the queries. This could be because:

  • The Keyboard Maestro Engine is locked up
  • The Keyboard Maestro Engine has crashed or quit
  • The system inter-process communication stuff has failed.

If the engine is locked up, you should see a spinning wheel on the status menu, and Activity Monitor sample should help determine where it is locked.

If the engine has crashed, then a crash report would help, or if it has quit, then relaunching it and figuring out why it quit.

I have very occasionally seen the system interprocess communication stuff fail, restarting is the only solution to this.

With menus, the test requires the Keyboard Maestro Engine to scan through the menu bar of the target application, which can take a bit of time as the accessibility API is painfully slow. Also, if the application is particularly adept at screwing up accessibility, it is actually possible to create loops in the structure which then makes the test take forever. I haven’t seen this with menus, but I have seen it with windows, and it is certainly possible that a sufficiently clever application could mangle the menu’s accessibility.