Karen Maymartin / Instagram

How to Run TextEdit as sudo

Listen, if you need to ‘sudo’ edit something you probably should have enough technical expertise to use nano or one of the other command-line text editors, but if you must, the key is to call the executable file rather than the .app.

You can find this by right-clicking on TextEdit.app and choosing “show contents”. Navigate down into Contents > MacOS > TextEdit. That is the TextEdit to target on your command line.

Right-click on TextEdit.app and choose "View Package Contents"

Right-click on TextEdit.app and choose “View Package Contents” to access the file tree containing the executable. 

The path to the TextEdit executable is Contents srcset=

MacOS > TextEdit” width=”1024″ height=”667″> The path to the TextEdit executable is Contents > MacOS > TextEdit

So your command line will be constructed like this:

sudo {drag TextEdit executable here} /path/to/file/you/want/to/edit

If you were editing your /etc/hosts file it would look something like this:

sudo /System/Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts

You will be prompted to enter your computer password to continue.

You might also get some garbage on in the terminal that you can ignore that looks like this: 

2024-01-24 12:42:30.456 TextEdit[33534:1263353] TISFileInterrogator updateSystemInputSources false but old data invalid: currentCacheHeaderPtr nonNULL? 0, ->cacheFormatVersion 0, ->magicCookie 00000000, inputSourceTableCountSys 0
Keyboard Layouts: duplicate keyboard layout identifier -17410.
Keyboard Layouts: keyboard layout identifier -17410 has been replaced with -28673.
Keyboard Layouts: duplicate keyboard layout identifier -30769.
Keyboard Layouts: keyboard layout identifier -30769 has been replaced with -28674.
Keyboard Layouts: duplicate keyboard layout identifier -14934.
Keyboard Layouts: keyboard layout identifier -14934 has been replaced with -28675.

Once you are in TextEdit you can edit and save as you normally do, then close TextEdit.

If you want to be tidy, you can then close your terminal session by pressing control-c and then exit the terminal app.

 

Groot photo by Karen Martin

Would you like to post a comment?

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>