Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Launch GUI programs as root UNIX
I was in the macosxhints chat channel, and someone asked about launching a OS X app as root without logging out, and without using Pseudo (which is a handy app, BTW). We came up with a fairly simple procedure for doing in the Terminal what Pseudo does normally on its own:
  sudo path/to/application/Contents/MacOS/app_name &
For example:
  sudo /Applications/TextEdit/Contents/MacOS/TextEdit &
That will launch the TextEdit program as root, and the ampersand backgrounds the process so you can get your Terminal back. You will be prompted for your login password (as is standard sudo behavior), and then the app will launch with full root privileges.

[robg adds: I tested this with TextEdit and used it to edit the httpd.conf file. It let me modify the file and save the changes, which proves that TextEdit was running as root. Be careful with this, though, as there's no indication as to which apps you've launched as root, and you would not want to accidentally change a system file that you did not mean to modify!]
    •    
  • Currently 3.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[17,789 views]  

Launch GUI programs as root | 19 comments | Create New Account
Click here to return to the 'Launch GUI programs as root' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Launch GUI programs as root
Authored by: macubergeek on Apr 01, '03 10:56:41AM

just use vi



[ Reply to This | # ]
Launch GUI programs as root
Authored by: kramrm on Apr 01, '03 10:57:42AM

wouldn't it have to be:
sudo open /path/to/application.app

I tried without the OPEN, and only received errors.

sudo open /applications/textedit.app
worked just fine.



[ Reply to This | # ]
Check the command...
Authored by: robg on Apr 01, '03 12:12:19PM

No 'open' is required as the path digs into the actual app bundle; you'll need 'open' if you do it the way you listed...

-rob.



[ Reply to This | # ]
then there's a typo in the hint
Authored by: huzzam on Apr 01, '03 02:54:50PM

the hint doesn't say to use "open". should probably be fixed.

thanks
--peter



[ Reply to This | # ]
duh never mind
Authored by: huzzam on Apr 01, '03 02:56:20PM

i misread rob's comment. call it an april fools' joke;)



[ Reply to This | # ]
Launch GUI programs as root
Authored by: gatorparrots on Apr 01, '03 12:10:14PM

This thread on the forum site contains much more complete information about launching GUI applications as root:
http://forums.macosxhints.com/showthread.php?s=&threadid=9872
The hint posted here only shows how to open a Cocoa application as root, but not a Carbon application. The forum thread will show you how to open both kinds of programs as root.

Also, if you have the system appearance set for "Graphite" in the General system preference pane, then a GUI application launched as root will have an "Blue" apple for the Apple Menu icon. This is the easiest way to distinguish between which applications were launched as root and which ones were launched as a normal user.



[ Reply to This | # ]
GUI programs as root, e.g. anti-virus apps
Authored by: tjj on Apr 02, '03 01:58:23AM
Very useful when trying out e.g. virus scanners. Presently, I am testing Norton beta v. 9, which refuses to scan some files unless run as root. The command: sudo /Applications/Norton\ Solutions/Norton\ AntiVirus.app/Contents/MacOS/Norton\ AntiVirus works

[ Reply to This | # ]
GUI programs as root, e.g. anti-virus apps
Authored by: tjj on Apr 02, '03 02:04:29AM

err, the backslashes escaping spaces disappeared when submitted, sorry about that. Perhaps without coding works better like this:
sudo /Applications/Norton\ Solutions/Norton\ AntiVirus.app/Contents/MacOS/Norton\ AntiVirus



[ Reply to This | # ]
backslashes to escape spaces
Authored by: gatorparrots on Apr 02, '03 10:46:52AM
Using quotes to escape backslashes is much more effecient (less keystrokes) for escaping spaces, not to mention being friendlier to GeekLog:

Backslashes
sudo /Applications/Norton\ Solutions/Norton\ AntiVirus.app/Contents/MacOS/Norton\ AntiVirus vs.
Quotes
sudo "/Applications/Norton Solutions/Norton AntiVirus.app/Contents/MacOS/Norton AntiVirus"

[ Reply to This | # ]
Launch GUI programs as root
Authored by: notmatt on Apr 01, '03 12:39:04PM

You can get a subtle indication of what's running as root and what not if you set root's colouring to the opposite of whatever you use. I use Graphite on the desktop, and root runs as Aqua; anything running as root will be in Aqua (such as Force Quit, as well as anything started as in this hint.)

I've been using this trick forever, since it's a relatively standard Unix thing. Sorry for not sharing.



[ Reply to This | # ]
Launch GUI programs as root
Authored by: Han Solo on Apr 01, '03 01:50:05PM
That's kinda cool, but how did you change the color scheme for root? (Specifically, how can one do it without enabling the root account -- via sudo somehow?) Seems like it would be a good idea(TM) for Apple to implement this more generally: perhaps a nice red Apple menu icon in such circumstances....

[ Reply to This | # ]
Launch GUI programs as root
Authored by: ashill on Apr 01, '03 05:18:46PM
Open System Preferences as root.
sudo /Applications/System\ Preferences.app/Contents/MacOS/System\ Preferences


[ Reply to This | # ]
Launch GUI programs as root
Authored by: pixelcort on Apr 01, '03 05:30:04PM

lol

This shows you that the 'environment for sudo'd apps actually works like it's that user. Very cool.

BTW, IMHO, sudo open App.app is much cleaner than sudo App.app/Contents/MacOS/App . For one thing it won't open multiple copies of the same app, but instead open the existing running copy.



[ Reply to This | # ]
Launch GUI programs as root
Authored by: ashill on Apr 01, '03 05:39:03PM
Agreed, except that
user% sudo open /Applications/System\ Preferences.app/
opens System Preferences as user, not root; running the file the other way opens it as root.

I'm not sure why this is.

[ Reply to This | # ]

It's deliberate
Authored by: owain_vaughan on Apr 02, '03 08:06:33AM

'sudo open' used to work for opening GUI apps, but this behaviour was changed to prevent people accidentally doing it...



[ Reply to This | # ]
Launch GUI programs as root
Authored by: luserpete on Apr 02, '03 12:54:30AM

the hint should read:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit &

it doesn't work as written



[ Reply to This | # ]
Reasoning for the command syntax
Authored by: NeuralNet03 on Apr 04, '03 11:25:48AM

I discovered, while I was writing this, that "sudo open <filepath" won't launch as sudo. /me thinks it's because sudo executes an Apple app called "open" that digs into the app package and opens the app. Problem is, the app doesn't get executed as root....only the package opener does. Not sure why that is the way it is, but this seems to work pretty well (for Cocoa apps...)

Someone asked on the channel a few days ago about launching the Finder as root (via this tip)

It -CAN- be done (maybe), but I'm not quite sure how, and I don't have an extra OS X machine to mess with (this old iMac is my primary and only X machine, so...) maybe when I get a new Tower, I'll have a few days to waste on getting a root Finder up and running.



[ Reply to This | # ]
Launch GUI programs as root
Authored by: englabenny on Apr 05, '03 07:37:27AM

Well this is basic, but I thank you all for it - the tip to change appearance of the root worked fine and is great, but I have another Q:
Is is possible to open an App as a different user than the current or root? For example if I want to just quickly change another users prefs or manage his iTunes Library?

I know "su benny" then "open -a iTunes" does not work, but is there not a workaround?



[ Reply to This | # ]
Launch GUI programs as root
Authored by: Usr bin Login on May 05, '03 07:53:12PM
Is is possible to open an App as a different user than the current or root? For example if I want to just quickly change another users prefs or manage his iTunes Library?

I know "su benny" then "open -a iTunes" does not work, but is there not a workaround?


Try:
su - user

That should ensure that not only are you running as that user, but with that user's environment variables as well.

from man su:
-l Simulate a full login. The environment is discarded except for HOME, SHELL, PATH, TERM, and USER. HOME and SHELL are modified as above. USER is set to the target login. PATH is set to ``/bin:/usr/bin''. TERM is imported from your current environ- ment. The invoked shell is the target login's, and su will change directory to the target login's home directory. This option is identical to just passing "-", as in "su -".

Usr bin Login

---
--------


QA implies some sort of quality to begin with.

[ Reply to This | # ]