
Go to Finder and right click and you shall find the option in the context menu to launch the input (the selected file) as root / superuser Open System Preferences > Keyboard > Services and verify that the script appears and is checked off. Open -a /Applications/Developers\ Tools/Sublime\ Text.app workflow - suggested name "Open in Sublime Text (as root) Paste the snippet below in the Shell Script action box Sudo open "/Applications/Developers Tools/Sublime Text.app" /etc/hostsĪlias - entry: alias edit="sudo open /Applications/Developers\ Tools/Sublime\ Text.app"Īutomator - Quick Action (for use in Finder):Īdd 'Run Shell Script' Action to workflowĬonfigure workflow options to be - Workflow receives current files or folders in Finder.app (bolded words are options to select) Terminal (bash/zsh): sudo open /Applications/Developers\ Tools/Sublime\ Text.app /etc/hosts Just to close the loop on this (because it was one of the top hits on Google). Simply copy the /etc/hosts file to another location, edit it there, and then use sudo to copy the modified file back to /etc. Use a GUI-based text editor that has the feature to prompt for your admin password when needed (I believe BBEdit can do this, for example) Use a command-line editor such as emacs, pico, or vi. To edit files like /etc/hosts, I recommend finding another way: This isn't a bad thing, though, as running a GUI app as root is generally a terrible idea for security, as there are many ways to surreptitiously inject code into a Cocoa app, and if that app runs as root, you can open up some pretty serious security vulnerabilities this way. I don't think you will be able to find a way to get it to run as root.

This is by design TextEdit is a sandboxed app, and running it as root would defeat much of the purpose of sandboxing. On the current version of macOS (10.12.6 at the time of this writing), this will not work from the shell either: $ sudo /Applications/TextEdit.app/Contents/MacOS/TextEditĪnd if you check the crash logs, you'll find the following: Sandbox registration internal error: Incoming message euid:0 does not match secinitd uid:501.
