Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X: Setting at runtime the Application name as it appears in Dock and Menu Bar

Tags:

macos

dock

I have an app that may get launched with current user's or with root permissions.

In fact, there's the possibility that the app runs twice at the same time - once under the current user and once as root.

I like to inform the user when the app is running under root. Currently, I show this in its window title, but I'd prefer to change the app's name so that it reads "Appname (Root)" where appropriate. That way, the name would appear both in the menu bar and in the Dock with this "root" info, and it would allow the user to tell which of the two app instances in the Dock is the root version.

Does someone know if the app name can be changed by code, i.e. by the app itself, or by its launcher?

If not, my only option appears to be adding a badge to the Dock icon that says "root", but that's my last resort, as it won't work for the menu bar nor for other tools that display the app names (i.e. other app launchers such as DragThing).

like image 272
Thomas Tempelmann Avatar asked Dec 16 '09 22:12

Thomas Tempelmann


People also ask

How do I customize my Mac Dock menu bar?

On your Mac, use Dock & Menu Bar System Preferences to change the appearance of the Dock, and to select items to show in the menu bar and in Control Center. To change these preferences, choose Apple menu > System Preferences, then click Dock & Menu Bar .

What is the app bar at the bottom of a Mac called?

The Dock on the Mac desktop is a convenient place to access apps and features that you're likely to use every day—for example, Launchpad and the Trash. The Dock can show up to three recently used apps that aren't already in it and a folder for items you download from the internet.

How do I change the icons on my Mac Dock?

After pulling up Finder > Applications, find the app you'd like to change the icon for. Right click and select Get Info or use the keyboard shortcut command + I. Now just drag the new image you want to use on top of the existing icon (you can also copy the new image then paste it onto the existing icon).


1 Answers

…there are at least five application names floating around, at least in concept: (1) the file name the Finder sees, which in the case of an application package is the package (bundle) name; (2) the name of the executable inside the package, (3) the long name used in many places for display purposes only; (4) the short name used as the application menu title and in a few other places where a long name won’t fit for display purposes; and (5) the process name of a running application. They aren’t always the same, especially in Microsoft and Adobe products.

—Bill Cheeseman

From what I can tell, the name in the dock is the name of the application bundle (sans ".app") on the filesystem.

The value under the CFBundleName key in info.plist is what shows up in the menubar.

As far as I know, changing either these at runtime isn't going to work… but what you can do is have two versions of your app, a root and non-root version, inside your user-facing .app bundle. When the user-facing app is launched, it checks if it's running as root or not, and launches the appropriate copy of the real app, which has theCFBundleName and file-name you want.

I wish I knew of a more elegant solution.

like image 143
Vincent Gable Avatar answered Sep 30 '22 19:09

Vincent Gable