Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open a menu in the application menu bar #2420

Open
ebai101 opened this issue Jul 17, 2020 · 4 comments
Open

Open a menu in the application menu bar #2420

ebai101 opened this issue Jul 17, 2020 · 4 comments

Comments

@ebai101
Copy link

ebai101 commented Jul 17, 2020

I'm trying to bind a hotkey to open the File menu. I'm coming from Keyboard Maestro, where there's a "Select or Show Menu Item" function that can just display a menu, and from there I can start typing the name of a menu item to select it. It doesn't seem like there's a way to do this in vanilla Hammerspoon, although I could be wrong - maybe there's an osascript-based solution?

@latenitefilms
Copy link
Contributor

Does this do what you want?

hs.application:selectMenuItem(menuitem[, isRegex])

@ebai101
Copy link
Author

ebai101 commented Aug 3, 2020

No, that doesn't work unfortunately. Here's an example - I want the code below to reveal the File menu in the frontmost app when I press F12:

hs.hotkey.bind({}, 'f12', function()
	hs.alert.show('showing the file menu')
	hs.application.frontmostApplication():selectMenuItem({'File'})
end)

I think this is the same quirk that I ran into with JXA (see here) where a simulated click on an item with no action doesn't actually do anything.

Let me know if I'm missing something. I'm on High Sierra 10.13.6 for what it's worth.

edit: that code works fine for me if I change the parameter list to a menu item that does have an action, like {'File', 'New Tab'} or similar (a new tab is created, if my browser is at the front)

@latenitefilms
Copy link
Contributor

Ummm, that's strange - you're code is working fine for me with Safari, but I'm on Mojave 10.14.6.

@latenitefilms
Copy link
Contributor

As a workaround, you could also use hs._asm.axuielement instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants