Pop-up menu selection

How can one select a pop-up menu that doesn’t have a menu bar equivalent? For instance selecting Apple Mail signatures. QuicKeys had such an option. I can’t find it in KM.

Popup menus are tricky to control as they often don’t have names or labels of any kind. To select a popup menu, you need to simulate a click on the menu, and then use typeahead to select the desired item, ie actions:

Click on popup menu
Insert Text by Typing “Menu Name%Return%”

The tricky part is clicking on the menu. First, make sure you have paused long enough to allow the window to come to the front, and then you can need to click on the popup. You can click in one of these ways:

  • if the window has keyboard focus, then you can click relative to the window, and if the popup menu is in a fixed location, then that may be a reliable solution.
  • click relative to the found image. If the popup menu always defaults to the same thing, then you can use the popup menu as the image. Otherwise, you need to click relative to something nearby that is consistent (like some label text).

To click relative to an image, you use the Mouse Click action, configure it to be relative to a found image, and take a screenshot of the desired area of the screen using Command-Control-Shift-4, and paste it into the image well on the action. The image has to be unique (which includes not being visible in the action if the image is small enough not to be shrunk in the image well) otherwise Keyboard Maestro will not know where to click. The Display option in the action will allow you to see where Keyboard Maestro is matching.

You can assign a shortcut to Mail signatures using the System Preferences keyboard shortcut controls.

1 Like

Really? I don’t see any options for that in there. Tell me more.

Assigning menus command keys in the system preferences is a useful way of improving the reliability of menus. A couple caveats though:

  • It often does not work on dynamic menus (if the menu is not populated until you click on it, the system does not know that their is a command in there with that menu item).
  • For use in Open/Save dialogs, you need to make the shortcut applicable to "All Applications" as the Open/Save dialog actually lives in its own application space.

Hey Edward,

Create a shortcut for Mail in the Keyboard–>Shortcuts–>App Shortcuts section of the System Prefs.

Give it the exact name of your signature and a keyboard shortcut. (On rare occasions you may have to quit and restart the app you’ve assigned a keyboard shortcut to in order for it to take.)

To produce a similar shortcut for your various email accounts insert the exact name and email address shown in the popup menu similar to:

Christopher Stone <listmeister@thestoneforge.com>

Basically this technique will work with any menu item the System can see - be it a popup menu item or a normal menu item. Unfortunately the implementation doesn’t give you much control, so you can’t specify something like:

Menubar–>File–>New Message



You can only say “New Message” or “None”, and if there are conflicts it can get a bit annoying.

I generally use the system for menu shortcuts, so I’ll have a visual cue for the keyboard shortcut - but I’ll turn to KM for these when it makes more sense to do so.

One pitfall is that sometimes pop-up menus aren’t populated until they’re activated, so in essence the system doesn’t see their contents ahead of time - and keyboard shortcuts don’t work at all OR only work after you’ve manually activated the menu once. (This is even true for some of the built-in keyboard shortcuts in the Sort-By and Arrange-By menus in the Finder, and that of course is a bug.)

Finally. Pop-up menus can generally be accessed by AppleScript and System Events UI-Scripting, but this method is not for the faint-hearted. (This method can sometimes solve those system-can’t-see-it issues.)

An example:

set emailAddress to "Christopher Stone <listmeister@thestoneforge.com>"
tell application "System Events"
  set quit delay to 0
  tell process "Mail"
    set frontmost to true
    tell front window
      if pop up button 2 exists then
        tell pop up button 2
          if value ≠ emailAddress then
            perform action "AXPress"
            tell menu item emailAddress of menu 1
              perform action "AXPress"
            end tell
          end if
        end tell
      end if
    end tell
  end tell
end tell