How i can get the Application Menu in Cocoa

前端 未结 4 1488
醉话见心
醉话见心 2020-12-29 08:15

How can I get the NSMenu or NSMenuItem for the application menu (the one in the menu bar next to the apple menu). It seems to be automatically created and independent from t

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 08:26

    my two cents for Swift 5.0

    private final func manageMenus(){
        let  mainMenu =  NSApplication.shared.mainMenu
    
        if let editMenu = mainMenu?.item(at: 1)?.submenu{
            for item in editMenu.items{
                print(item.title)
            }
        }
    }
    

    so You can also enable it:

    ....

      for item in editMenu.items{
           item.isEnabled = true
       }
    

提交回复
热议问题