Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
    
Awesome! Thank you. –  Clinton Blackmore Jul 30 '09 at 22:43
    
This is still the best answer, but I found an explanation that goes into lots of details as to how this works: mac-forums.com/forums/os-x-darwin-development/… –  Clinton Blackmore Mar 4 '10 at 18:39

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.

share|improve this answer
    
Pretty cool, Pseudo still works on Snow Leopard despite the outdated site and software. –  Cawas Mar 4 '10 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.