5

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.

7
  • 2
    Just like in X, root can't run the GUI and TextEdit is a GUI app.
    – Allan
    Commented Nov 30, 2018 at 14:48
  • If it is a plain text file you can do something like "pico /path/to/file.txt" and it will open for editing in the PICO text editor in the same terminal window. Commented Nov 30, 2018 at 16:42
  • Why root and not simply sudo? sudo can usually open a protected file in a gui. Commented Nov 30, 2018 at 17:00
  • @BenjaminScherer Using sudo open while logged in as a normal (well, admin) user doesn't do anything useful, because while open runs as root, the app it opens will be running as the normal user and not have root privs. Commented Nov 30, 2018 at 17:52
  • I have gvim installed (which is the gui edition of vim) and it does allow me to edit files in sudo mode Commented Nov 30, 2018 at 18:11

1 Answer 1

1

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .