Skip to content

Instantly share code, notes, and snippets.

@othyn
Last active January 30, 2024 10:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save othyn/98f35abf988bdcfb6a118b8573d46b3b to your computer and use it in GitHub Desktop.
Save othyn/98f35abf988bdcfb6a118b8573d46b3b to your computer and use it in GitHub Desktop.
How to disable default menu bar items in Swift / SwiftUI for macOS
//
// App.swift
//
// Created by Ben Tindall on 30/03/2022.
//
import Foundation
import SwiftUI
import Cocoa
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillUpdate(_ notification: Notification) {
if let menu = NSApplication.shared.mainMenu {
if let file = menu.items.first(where: { $0.title == "File"}) {
menu.removeItem(file);
}
if let edit = menu.items.first(where: { $0.title == "Edit"}) {
menu.removeItem(edit);
}
if let window = menu.items.first(where: { $0.title == "Window"}) {
menu.removeItem(window);
}
if let view = menu.items.first(where: { $0.title == "View"}) {
menu.removeItem(view);
}
if let help = menu.items.first(where: { $0.title == "Help"}) {
menu.removeItem(help);
}
}
}
}
@main
struct AutoClickerApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
EmptyView()
}
}
}
@XboxOneSogie720
Copy link

Worked like a charm. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment