Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently find that a terminal command to open a file in TextEdit would be very handy. Does such a command exist on Mac OS X?

share|improve this question

migrated from Sep 23 '11 at 23:53

This question came from our site for professional and enthusiast programmers.

I'm trying to open Sublime Text from command line. I did "open -a /Applications/Sublime Text my_file.txt". It works but it creates a new window every time I want to open a file. Any fix? – Mohammad Moghimi Feb 13 '13 at 22:22
If you want it with sudo, gota open TextEdit in root mode first – cregox May 2 '13 at 11:26
up vote 147 down vote accepted

open -a TextEdit filename should do the trick.

The -a flag specifies any application you want, so it's applicable to any number of situations, including ones where TextEdit isn't the default editor.

Other relevant options

  • -t opens in the default editor (i.e. if you use BBEdit, TextMate, etc.)
  • -e will open the file specifically in TextEdit
share|improve this answer
Probably the best solution. – daviesgeek Sep 24 '11 at 2:27
If you want a program whose name has spaces, you'll need to escape them, e.g., open -a Adobe\ Photoshop\ CS6 image.png – meetalexjohnson Jun 3 '15 at 0:13
How to open it with SublimeText3 that stays in /path/SublimeText3? – Emerald214 Jan 14 at 9:51
In open command's manual, you will see -e Causes the file to be opened with /Applications/TextEdit. So open -e filename do the same thing, and is simpler. – Dawn Song Mar 31 at 11:47

Direct, easy answer - add an alias to your ~/.bash_profile like:

alias textedit='open -a TextEdit'

Invoke it like:

textedit theFiletoEdit.txt

The difference between this and the other answer, is you can easily remember it when you want it. Typing text and Tab to autocomplete it will make it instantly available

For those with a bit more bash background, who want the reasoning without having to fuss with figuring it out:

  • The problem is that a trivial symlink (or its ilk, like a shell script redirect) to /Applications/ causes a new instance of TextEdit to open the file you pass to it. This works, but does not give your expected Mac OS X default behavior. (if you try it, you'll see)

  • To get the default UI behavior, using the Mac built-in open command, with that '-a TextEdit' flag (that others mentioned) induces the Mac UI to have (any) currently running instance of TextEdit handle the call (with no inapropos 'sudo' needed for general case usage).

share|improve this answer

The open command can be used to open files (in their default apps, unless using the -a flag), URLs (in your default web browser), and directories (in Finder).

An example would be

open /Users/Example/Desktop/example.rtf
share|improve this answer
This is probably the easiest way to open text files for edit in a graphical editor from the terminal. – David Thomas Nov 8 '14 at 23:54

For those finding this post:

The solution was to use the command sudo open -t /path/file.txt

And the man pages for the open command also show how to do some other things like show the file in the finder.

share|improve this answer
Using sudo is unnecessary and undesirable. – Chris Page Sep 26 '11 at 13:29
Unless the file isn't accessible to the user otherwise. But in general, agreed. – Bobson Mar 2 '12 at 12:12
Actually, I just tried using this command with sudo to edit /etc/hosts on Lion and it just doesn't work (as expected). It doesn't allow me to edit the file. Only clone it. Might as well go without the sudo, in this case. The file will be marked as locked anyway. To really be able to do so, have to first open the TextEdit in root mode, or just use a different editor:… – cregox May 2 '13 at 11:22

This is not a programming question. But I did a quick google and found this site: pico: Simple text editor vi: Text Editor

And this site explains how to use TextEdit from terminal.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

None of those links demonstrate how to open the file in textEdit. – weezybizzle Sep 22 '11 at 9:20
The last link does. – SynerCoder Sep 22 '11 at 9:21
It absolutely does, thanks for adding that, you are a much faster googler than I. – weezybizzle Sep 22 '11 at 9:24
Does that work? Cause I have no experience with Mac OSX (Windows fan boy ^^) – SynerCoder Sep 22 '11 at 9:26
yup, does exactly what I wanted, thanks! – weezybizzle Sep 22 '11 at 9:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.