Is it possible to run a Mac OS X GUI app as root when you are logged in as a different user? [Yes, I recognize that this is usually a bad idea.]
When I try
sudo open /Path/To/My.app
it runs as the logged-in user, so far as I can tell.
[I'm sure you are wondering why I want to do this. Sigh. I am running NetRestore within a NetBoot image that was not created by NetRestore Helper, as I need to run some other GUI software after I do the restore. It logs into a standard administrator account. Normally when you run NetRestore, it asks you to authenticate before restoring. It appears that it determines that it is NetBooted and assumes that it is running under the root account, and refuses to ask for authentication, and thus has insufficient permissions to perform a restore.]
[Most likely I will have to tweak my netbooting setup so it automatically logs into the root account, but if I could just run the one application as root, it would take much less time to set up.]
[Yes, I could come up with another method to do a multicast restore, but NetRestore is proven, friendly, and still works under Leopard. As an alternative, I may use the asr command with iHook.]
Don't use
open
if you want to run as another user. Open launches the application you're asking for via LaunchServices which will load it as if you double clicked on it.If you however run the application binary directly it'll work. So for example, as root (so from a script that's already running as root, or via
sudo
) run/Applications/TextEdit.app/Contents/MacOS/TextEdit
and TextEdit will run as root.You may want to try Pseudo for this, as you can use it to launch apps with the sysadmin's privileges.
I am not quite sure what you are asking though. If you want something to run automatically, you can, I guess, use the launch document feature of the program to create a launch path. I haven't used this feature, but it may be something you want to look into.