tags:

views:

319

answers:

3

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).

A: 

That label comes out of your Info.plist and I don't believe it's ever consulted again after it's been launched. If you want to have a parent application that does nothing but launch the real application (possibly from inside its own bundle) after munging its Info.plist, then that might give you the effect you're hoping for. You will get two icons bouncing at launch time, though.

Azeem.Butt
Right, that's what I figured. Altering the Info.plist is not an option, though.
Thomas Tempelmann
+1  A: 
…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.

—http://www.cocoabuilder.com/archive/message/cocoa/2003/8/24/2349">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.

Vincent Gable
Well educated answer, thanks :)Your suggestion with two copies gives me an idea: I might be able to create some symlinks to an alternative "copy" inside my app. I'll try that out.
Thomas Tempelmann
Hey, that worked! I created a folder named "Appname (Root).app" inside my app's main folder, created a "Contents" folder therein, created symlinks to all the app's Contents items, and finally placed a modified Info.plist in there with the appropriate bundle name.
Thomas Tempelmann
A: 

OS X apps do not normally run with multiple instances. Look at any app developed by Apple for example. It would be more common to allow for multiple documents/windows, in this case each window could be either a root or non-root window.

The most common way to allow for root authentication however is to have a padlock icon that can be clicked to switch to root mode with a password prompt, this can be seen in many of the System Preferences panels.

Tobias Cohen
Tobias, I don't see what you're getting at.I know how to launch an app in root mode, and authenticate for it (I', using "AuthorizationExecuteWithPrivileges"), that wasn't my question.The problem is that the app is normally launched in non-root mode, and the user can request to launch it in root mode (thru AuthorizationExecuteWithPrivileges). For design reasons I cannot easily change, the user may end up with two running instances of the app, and I like to tell him which is which.
Thomas Tempelmann