Jeremy Friesner
Jeremy Friesner

Reputation: 73051

How to rename the program-name menu-label in a MacOS/X program?

I have a Qt-based GUI program that runs under MacOS/X, and I'd like to be able to change the label of that program's first menu-header, i.e. the label circled in red in this screenshot:

Example Apple program label with menu-label in question circled

Is there a programmatic way to do that? An objective-C/"native" solution would be sufficient, assuming no Qt-based solution exists.

Some background info (for those who rightly suspect an X/Y issue here): My MacOS/X software distribution includes several different Qt-based programs, and in order to avoid having to distribute multiple redundant copies of the shared libraries they all use, and avoid having to write a custom installer, all of the executables are placed into the Contents/MacOS subfolder of the same .app bundle, as shown in this screenshot:

MacOS .app folder software distribution layout

To run the software, the user clicks on the .app-folder's icon to launch the "main" application, and then there are various buttons/menus in that GUI that can launch the "other" applications as child processes as necessary; and that all works well, except that the child processes' first menu's label is always shown as the name of the "main" application (as listed in CFBundleExecutable tag in the bundle's Info.plist file) rather than the child-program's own name, and I'd like to be able to change that so it shows its own program-name instead.

Upvotes: 1

Views: 366

Answers (1)

sbooth
sbooth

Reputation: 16966

The following code (Swift, should be trivial to port to ObjC) changes the menu's name:

NSApp.mainMenu?.item(at: 0)?.submenu?.title = "child-program-name"

However, with this approach the menu is no longer displayed in bold once the name is changed since it doesn't match the app's name. In fact, even when changed back to the app's name the menu title is no longer bold. This seems to be a long-standing problem; see set titles of items in my app's main menu?. Unfortunately NSMenu doesn't have an attributedTitle property like NSMenuItem.

Upvotes: 1

Related Questions