How to change a macOS menu title in SwiftUI

I am able to insert, delete or replace items in the macOS menu bar using SwiftUIs CommandGroup command. Is it also possible to rename an existing menu title?

My goal is to replace the 'file' menu title with 'account'. The rest of the menu bar can stay as it is.

Replies

Hello:

Now it is not possible to change the title of a menu in SwiftUI natively. However, you can use the application delegate for this purpose: you must first create the AppDelegate class and override the applicationDidFinishLaunching(_ : ) method.

import cocoa

class AppDelegate: NSObject, NSApplicationDelegate {
     func applicationDidFinishLaunching(_ : Notification) {
         if let menu = NSApplication.shared.mainMenu?.item(withTitle: "Help") {
             NSApplication.shared.mainMenu?.removeItem(menu)
         }
     }
}

Then you have to set the application delegate in <application_name>App.swift with:

@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

Before the body attribute.

Greetings from Victor.-

Post not yet marked as solved Up vote reply of vrm1 Down vote reply of vrm1