If you're serious about protecting (usage of) your application with a password , hiding the menubar won't help much, as you already concluded.
To prevent anonymous users from performing actions that require authentication, you will actually need to create logic in your code for protecting these actions and checking if the user did in fact authenticate correctly, each time they try do something (select a menuitem or press a button).
Having said that, you can prevent anonymous users from for instance opening the preference-window by disabling the related menu-item. Personally I would much prefer actually disabling the relevant controls in the preference-window, so users can explore the different options, but also understand that they need to authenticate. You could follow the model Apple used for the macOS System Preferences window, which will lock many (but not all) Preference Panes, depending on the particular Pane, and whether or not the user did authenticate.
A good starting-point would probably be the relevant documentation on Apple's developer website. For instance: https://developer.apple.com/documentation/securityfoundation
And if you still just need want to hide the menubar, you can always just do:
[NSMenu setMenuBarVisible:(BOOL)onOff];
But I believe it's better to use the solution from @jatoben's answer, as NSApplication
's presentationOptions
because this allows you to really disable functionalirty. Just hiding the menubar with [NSMenu setMenuBarVisible:(BOOL)onOff]
does not disable shortcuts for the menuItems, so you still could show the preference-window using ⌘,
.
On a sidenote, I believe you would save yourself all this trouble if you would simply show your password-dialog using
NSModalSession session = [NSApp beginModalSessionForWindow:passwordDialog];
[NSApp runModalSession:session];
This shows you dialog modally for the application, meaning that all other windows and also almost all menuitems are automatically disabled…