Macro "Select or show a menu item" + key pressed

Hello everybody,

I would like to create a macro which selects a menu item with a key pressed simultaneously.
In this case I need to select iTunes’ “Information”-menu while the option key is pressed.
Can anyone please tell me how to do this?

Thanks in advance
LarryLayouter

Hello Larry,

I was hoping for menu selection with modifiers for exactly the same thing. I was able to make a shortcut with cmd-option-I to select that menu and it does the trick for now.

In other apps, menu items that change with modifier keys usually aren’t so hidden. For example, if you select File from the Finder, try keeping the menu open, and pressing modifiers such as option and shift-option; all those commands I’d guess are unavailable through KM at the moment. Perhaps this can be rectified in the future.

Thales

Hello Thales,
thanks a lot for your X-Mas-answer :wink:
What exactly did you do when you made “a shortcut with cmd-option-I to select that menu”? Did you only use KM?
I helped myself with an AppleScript using UI scripting triggering it with cmd-i - find it below (keep in mind it uses german expressions for the menues).
Merry christmas
Larry

tell application "System Events"
tell process "iTunes"
key down option
click menu item “Informationen” of menu 1 of menu bar item “Ablage” of menu bar 1
delay 1
key up option
end tell
end tell

Yes only KM. Just select the menu item and assign the shortcut cmd-option-I. Since option is held down when using the shortcut, it selects the menu with the option key.

  • T

I have the same question. I’d like to select a menu item that only reveals when i press the option key. How do i write such an action?

It depends on the application and how they do their menus. With well written applications, you can just use the Select Menu Item action. For example:

That will work without the option key being held down.

You can try using the Press and Hold Modifier action before the select menu item, but whether that will work or not si still dependent on the application's behaviour.

I am trying to make a file open with a specific (not default) application, in Finder.
"Always Open With" and then the application.
Most of the times it does not work, i can't get my finger behind it. If i do it with my mouse the specific (but not default) application is sticked to the file, but with the KM action it is not.

Any idea?

Because it is a dynamic menu, the menu is probably not being generated by the Finder until it is open.

Try either:

or

You might need a pause between the two macros to allow the menu to appear and be populated.

I ended up using this. It is not always working for some reason, most of the time only the second time. Don't know why.

This worked for me using the Finder, to select "Library" when the OPTION key is held down with the "Go" menu activated:

2017-06-28 17:10 CT
• Add Pause after Hold Down OPT Key

I think that is the same, isn’t it?

Not quite. I’m holding down the OPTION key BEFORE I type the name of the desired menu item. I think this is necessary to ensure the item appears before trying to select it.

To be safe, you might even need to add a small pause (~0.2) AFTER the “Press and Hold the Option Modifier” Action, in order to give the app time to respond to the OPTION key.

will try, thanks!

Fail. And, that is as expected because then i am not typing VLC the but option-v, option-l, option-c

I just added this Pause to my above post of the macro.

I ended up with this and it seems better now

That is not how it works for me.
I tested this in both Finder and BBEdit, and it works.

In BBEdit, if I manually hold down OPT, and type "Lib", I get this:

Òˆ∫

But if I run the Macro (without the Finder menu), I get this:

Lib

So on my system, somehold using the KM Action:

and then

does NOT use the OPTION key when doing the typing.

I'm running Keyboard Maestro 7.3.1 (7.3.1) on macOS 10.11.6.

@peternlewis, can you please tell us what the expected behavior is for this scenario?

If the system sends any events, they will have the modifiers set to the real modifiers.

If Keyboard Maestro sends any events, it will have the modifiers set as configured in the action.

So Press and Hold a Modifier is generally only useful when other things are happening. Such as launching an application:

Even then the application may choose to look at the hardware modifiers.

Of course, typing the "Lib" will release the option key. I believe it will then be re-pressed.

It's possible in @Fokke's final example, that simply using Type a Keystroke:Option-Enter would work, but probably better is the Press and Hold the Option key, Pause briefly, and then type Option-Enter.

A lot of this comes back to how the application handles the events: does it handle the event and then check the modifier, or does it watch for the modifier while the menu is open and adjust the menus, and when selected, based the decision on the current state of the adjusted menu.

1 Like