Menu Item Is Clicked But Does Not Toggle

I have a macro that clicks a menu option that toggles on and off. The macro executes successfully (ActionResult is OK); however, the menu option does not toggle.

If I use AppleScript code in the Apple Script Editor to toggle the menu option, then the toggle works correctly; however, if I place that AppleScript code in the KM macro, the menu item does not toggle.

I have tried placing a pause before the menu item click, but that doesn't seem to affect the process. The application in question is Finale. I haven't tested this in other applications.

Thanks in advance for any help.

Finale - Speedy Entry - Toggle Jump To Next Measure.kmmacros (2.9 KB)

Hey Scott,

You have the Execute an AppleScript action disabled in your macro.

-Chris

I have a feeling you've left out some details...

Please post a screenshot of the menu item in question.

Both toggle states (if they're different).

I'm guessing you were trying both methods in the same macro, alternating which was enabled -- if not, try enabling the action :wink:

Otherwise, try "staging" the menu selection by clicking the menu, then the menu item. Both methods shown below, but you may have to tweak because I don't have Finale to test against:

Finale - Speedy Entry - Toggle Jump To Next Measure copy.kmmacros (3.4 KB)

Image

We're seeing a lot more "dynamically populated" menus these days, where items aren't available until the parent has been selected. This might be one of those cases...

1 Like

The AppleScript macro was disabled, so that I could test the Select Menu action. Only one of these actions was executed when the macro was run, so I was not clicking the menu option twice.

Here are screenshots of the menu. The Jump To Next Measure is always enabled when the Speedy Entry tool is active (which it is for this process).

To display the checked/unchecked versions of the menu, I clicked on the menu option with my mouse.


I tried the same scenario with the Calendar app (since that is one that everyone would have). I used a macro to toggle the "Show All-Day Events" on the View menu. That menu option toggled successfully.

I noticed that toggling that menu item triggers a redraw of the screen. The Jump To Next Measure in Finale does not. I put a Pause after the Jump To Next Measure (as much as 0.5 seconds), but it had no effect.

I then recalled that Finale has a menu item to redraw the screen, so I added a click on that menu item after the Jump To Next Measure, but it did not affect the toggle of the Jump To Next Measure menu item. I tried putting a pause between the two menu options but that had no effect either.

I then tried two other Finale menu options that toggle. One of them (Document > Keep Octave Transposition in Concert Pitch) would cause a redraw of the screen (but does not apply affect my document). The other was Finale > Check for Updates Automatically. Both of these toggled successfully.

Maybe this information will help someone to figure out what is going on.

Did you pick your menu in the select-menu action via the menu-picker, or did you just type it in?

Run this from Apple's Script Editor.app:

tell application "System Events"
   tell process "Finale"
      tell menu bar 1
         tell menu "Speedy"
            return name of menu items
         end tell
      end tell
   end tell
end tell

Then toggle the menu item, and run it again. See if there's a difference.

(Lists all menu items – not just the one you want.)

I'm not sure from the above, but did you split the "click menu item" into two separate actions -- "click Speedy" and then "click Jump to Next Measure"? Try putting a small pause, like 0.2s, between them.

I tried what you suggested. The name of the menu item did not change after toggling it. The properties returned for that menu item are:

I tried what you suggested. The name of the menu item did not change after toggling it. The properties returned for that menu item are:

{
  minimum value:*missing value*,
  orientation:*missing value*,
  position:{
   652,
   118
  },
  *class*:*menu item*,
  accessibility description:*missing value*,
  role description:"menu item",
  focused:*missing value*,
  title:"Jump To Next Measure",
  size:{
   266,
   22
  },
  help:*missing value*,
  entire contents:{},
  enabled:*true*,
  maximum value:*missing value*,
  role:"AXMenuItem",
  value:*missing value*,
  subrole:*missing value*,
  selected:*false*,
  name:"Jump To Next Measure", description:"menu item"
}

Also, I selected the menu item from the picker in KM. I did not type in the values.

1 Like

I have the two click menu item actions as separate actions. I have a 0.2s pause between them. The menu item still does not toggle.

Well, I'm out of ideas for now...

I figured out a solution.

I select the Speedy menu first (without selecting a submenu item). This causes the Speedy menu to appear. Then, I select the Jump To Next Measure submenu item, which results in a successful toggle.

Screenshot 2023-01-23 at 1.03.01 PM

1 Like

It turns out that I needed to put a 0.2sec pause between the two menu clicks.

I also discovered something else. There were times that the menu item still would not toggle with this new approach. I realized that I was holding down Ctrl-J after I triggered the macro, which caused the Ctrl key to be active when the click was made on the submenu item. Apparently, a Ctrl-Click on a menu item will not toggle it, so I have to remember to release the Ctrl key immediately after typing the 'J'.

Or you can use a Wait action to pause until the ctrl and J keys are up.

In Mac Automation where you're driving the UI timing is often an issue. Keyboard Maestro can frequently drive the macOS faster than it can keep up, so you the user must always keep this in mind.

Glad you got things figured out.

Your solution was what @Nige_S was suggesting in post #8 above – was this not clear to you? (Not criticizing – just asking for future reference.)

This double-activation solution has been around for a long time and was developed to deal with apps that had dynamic menu construction, and I think this is the first time I've heard of someone needing to place a pause between the two menu actions – although that's not shocking at all – especially on the first run of the macro (opening and populating of the menu).

I had used the pause between two menu selections in the previous scenario. The difference in this scenario is that the first menu click was just the parent menu item, and the second menu click was the submenu item.

In the previous scenario, the first menu click was the submenu item that I wanted to toggle, and the second menu click was an item to redraw the screen that was on a different menu. That scenario did not result in the submenu item being toggled.

The solution was to click the parent menu, pause 0.2sec to give it a chance to be displayed, then click the submenu item.

I have not had an issue with any other submenu items; it appears that this issue occurs only when the menu item needs to be toggled.