How to remove items from default NSMenu

Hello:


My default NSMenu has items which are not applicable to my app. How can I remove the unwanted items?


func applicationDidFinishLaunching(_ aNotification: Notification) {
        item = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
        func removeItem(at: Int){
          
        }


What is the code for line 4?

The Default menu has the following:


App name, File, Edit, Format, Window, View, Help. I want to remove 4 of these.

Replies

Why don't you remove directly in Interface Builder ?


Have you defined an IBOutlet for the menuBar ?


    @IBOutlet weak fileprivate var menuBar: NSMenu!

Edit your storyboard or xib. Removing them via code as Claude31 suggested is correct if you're bound and determined not to edit the resources.

Actually, If you go the programmatic way, it is recommended to do that in applicationWillFinishLaunching, before the system inserts some of it's own menu items. I'm sorry I can't find the link to where I've read that (I think it was a technical note or a release note), but I remember it was from Apple.


Hope it helps.