SwiftUI, macOS, how to hook up to Edit menu's commands?

In SwiftUI on macOS, you can add items to the main menu by using things like CommandGroup, CommandMenu.

But the default menus already have items. For example, the Edit menu has Undo, Redo, Cut, Copy, Paste, Delete, Select All. Those menu items are grayed out and don't do anything. Is there a way to hook some Swift code to these? Or do you just use CommandGroup(replacing: ...) to replace them? That doesn't seem right; why put them there if you just have to replace them?

Besides hooking up a function to run when they get clicked, I'd like to know how to enable and disable them depending on app state.

        WindowGroup {
            MyContentView()
        }.commands {
            SidebarCommands()
            CommandGroup(after: .newItem) {
                Button { newFolder() } label: { Text("New Folder") }
                    .keyboardShortcut("n", modifiers: [.command, .option])
            }
        }

You can replace those (as you wish) as you mentioned in your question.

CommandGroup(replacing: .newItem) { EmptyView() }

or

CommandGroup(replacing: .newItem) {  }

According to the document. You can’t modify or remove the Apple menu items as expected. Which is actually, perfectly reasonable.

The Apple menu, which is always the first item on the leading side of the menu bar, includes system-defined menu items that are always available. You can’t modify or remove the Apple menu

Best

SwiftUI, macOS, how to hook up to Edit menu's commands?
 
 
Q