Home > Net >  How can I remove all commands in macOS?
How can I remove all commands in macOS?

Time:11-16

I am trying to remove every commands in macOS with help of .commandsRemoved() which is doing good job, but I can see there is some that did not get removed like ShowTabBar or ShowAllTabs:

@main
struct testApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .commandsRemoved()
    }
}

enter image description here

CodePudding user response:

You cannot remove the app title menu on the bar, but the following will work to remove all of the commands under it. First, add the following line of code to your App struct:

@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

Then, create a new file called AppDelegate (or whatever you will remember - this can also be in the same file). Create an AppDelegate:

//In the file, you must import `AppKit`

class AppDelegate: NSObject, NSApplicationDelegate {
    func applicationWillFinishLaunching(_ notification: Notification) {
            NSWindow.allowsAutomaticWindowTabbing = false //<-- This is the key!

            //This will hide all of the fullscreen and tab menu controls
        
    }
}

This code was tested with Xcode 14 and macOS 13.

References

https://www.hackingwithswift.com/forums/swiftui/what-s-the-swiftui-way-to-do-this-appdelegate-thing/10559

https://stackoverflow.com/a/65634944/20384561

https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing

  • Related