How do I start TextEditor from the command line?

I work a lot at the command line in a Terminal and would like to start a text editor on a certain file. I'm from Linux Land and normally use kwrite or gedit from a bash shell. Trying to find the Mac equivalent, as a guess, tried

user> textedit somefile.txt 
user> texteditor somefile.txt 
user> TextEditor somefile.txt 

and other variations. I can't seem to find the proper name of the text editor app. (No, vi isn't to my liking.) Oddly, the guy at an Apple store didn't know this.

2,273 13 13 gold badges 34 34 silver badges 46 46 bronze badges asked Jun 27, 2011 at 18:15 5,193 7 7 gold badges 29 29 silver badges 23 23 bronze badges

Both Nathan and mipadi provide answers, but I think they're only partial answers, so I added one. I'm not sure if it would have been better to combine their responses somehow, and if so, how to have done that.

Commented Jun 27, 2011 at 19:07

@Viktor it generally isn't good to re-post things that people have already said, and exact duplicates are removed. Since you had something to add, good ways to go would be an answer saying "In addition to Nathan and mipadi's techniques. ", or comments on those answers with your addendums. What you've done here is okay, but not exactly a 'best practice'. Thanks for asking; now you know for the future :-).

Commented Jun 27, 2011 at 21:27

10 Answers 10

Here are some possible answers, all using the 'open' command-line utility.

The -a option means "open the file argument with the named application":

open -a TextEdit file.txt

The -e option means "open the file argument with the TextEdit application":

The -t option means "open the file with the default application for editing text files, as determined via LaunchServices". By default, this will be /Applications/TextEdit.app; however, it's possible for this setting to get overridden:

Finally, any file that's of the "text" type will get opened by the application bound to the text type if you just say open file.txt . You can use the "file" command to reveal what the operating system thinks the file type is: file file.txt . So, for example, if you renamed "file.txt" to just "textfile" then open textfile would still open it in the default text-file editing application, as long as file textfile still thought that "textfile" was actually a text file.

A short 'help' file on open can be found by running

open --help 

Or you can read the whole manual with

man open