Why is it that I cannot open file in terminal when in root? I have a file in MacOS that I want to change that is protected by permission restrictions. I cannot access it with my normal account. I use terminal to log in to root, and try to open the file as such:

open -a "TextEdit.app" file


However, the terminal returns the following error:

LSOpenURLsWithRole() failed for the application /Applications/TextEdit.app with 
error -10810 for the file ...


The open command works for my normal user account on files, but when terminal is logged into root, the command returns this error.

I have looked at many articles, but none seem to solve the problem. 

Thanks for any help.
I believe you're using su or similar to login to the root account while in your normal account. While you are using Terminal, any action taken in the Terminal.app will have the same root user level access.

However, once you leave the Terminal.app, such as when you use the open command, that opened app does not inherit the special permissions from root. It sends you back to normal land where your user account is limited.

To workaround this, you can use a text editor available in root. A short list includes vi, vim, nano, emacs, pico. I'm a fan of nano as it shows most of its commands in the window. You can use the following command in your normal user to edit a file like so:

sudo nano /some/file.txt

The command to save (write out) is control+x (^O), and quit (exit) is control+x (^X). Good luck!