How to collapse a submenu(NSMenu) programmatically on macOS

I am currently working on a status bar app on macOS, After the user opens the bar menu by press shortcut key and entered a submenu, I want to use the ESC key to collapse a submenu, but I can't found a solution to collapse a submenu programmatically anywhere.

Replies

Could you explain more in detail.


I tested a MacOS App (not a status bar app).

I click on Menu in the bar, it displays

I type ESC, that hides the submenu.


I tested with Apple menus like Time or keyboard, work the same.

-> Is it the same for you ?


Hi @Claude31
thanks for your reply, I think you just test the 1 level menu, but if you test 2 level menu, you found ESC will close all menu, I just want close current level submenu.

Seem no solution for that. I give up to do that. thanks for your attention, if you have any solution, Please share with me, thanks.

Hi @Claude31 
Sorry I've confused you.
Example in Safari menu bar:
  1. open menu Safari -> Bookmarks -> Favorites

  2. focus mouse on submenu Item in Favorites,

  3. press ESC ,

you will see all menu closed,
but I want only close Favorites submenu.