Is there a SwiftUI idiomatic way to selectively remove the defualt (File, Edit, View, Window) menus from the menu bar in a macOS app, while keeping other menus like the AppName menu intact? The app I’m building is a simple utility app, and Edit and View menus are not relevant in this context. Any guidance would be appreciated.
Replies
The answers to the following Stack Overflow question may help you:
-
They won’t. The highest voted solution is quite inelegant since it’s hardcoding strings, and my app is localized in numerous languages. I would need to find the menu names for each language and then match the strings. The other, where someone suggested using UIMenuBuilder – that API isn’t available on macOS, and I’m not using Mac Catalyst.
Four years after the introduction of SwiftUI
, the framework still lacks a clean, straightforward, idiomatic way to remove the default system CommandMenu
top-level containers – specifically, File
, Edit
, and View
.
Scenario 1: a utility app is designed to disable the zoom button and full-screen mode, doesn’t use tab bar, toolbar or sidebar – the View
menu will be empty upon build. Despite this, the View
menu remains visible even though it’s completely empty. This is clearly a bug.
Scenario 2: a utility app lacks text entry, and has no need for undo/redo or copy/paste, the Edit
menu becomes unnecessary. However, the operating system automatically injects Autofill
, Start Dictation
, and Emoji & Symbols
submenus and commands into the Edit
menu. Another clear bug.
Scenario 3: when using Window
instead of WindowGroup
to present a Scene
in a single, unique app window, macOS still provides a Minimize All
option if you hold the Option key while clicking on the Window
menu, even though the app has, and can only ever have a single window. Although the zoom command is intentionally disabled as mentioned above, it becomes re-enabled as Zoom All
when the Option key is held while clicking on Window
menu. This is not a bug. This is carelessness.
Why is there a File
menu in the System Settings
app, which doesn’t deal with files (saving, exporting, printing, etc.)? More perplexing is the presence of a Close All
command when the Option key is held down and the File
menu is clicked.
A complete lack of attention to detail and quality control on Apple’s part.
-
Filed under FB13324789, FB13324866, and FB13324935.
Btw, I’m aware of the new .commandsRemoved(), available since macOS 13, but that apparently removes all menus.
If you attempt to remove all commands using
.commandsRemoved()
, then add back only the necessary ones using.commandsReplaced { CommandGroup(replacing: .help, addition: {}) }
, such as.appInfo
,.appVisibility
,.appTermination
, etc., theAppName
menu will still remain empty.