Automator: Run TextEdit as Root
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 
Password:
Illegal instruction: 4


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


This is by design; TextEdit is a sandboxed app, and running it as root would defeat much of the purpose of sandboxing. I don't think you will be able to find a way to get it to run as root. 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.

To edit files like /etc/hosts, I recommend finding another way:


Use a command-line editor such as emacs, pico, or vi.
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)
Simply copy the /etc/hosts file to another location, edit it there, and then use sudo to copy the modified file back to /etc.