Apple - How can I open a text file with TextWrangler from the Terminal (command line)?

As a one-time thing,

open -a /Applications/TextWrangler.app myfile.txt
open -b com.barebones.textwrangler myfile.txt # same thing by ID

You can also create an alias for opening TextWrangler, that you would put on the .bash_profile file, which is an hidden file by default that is usually in your home directory.

This is the command that you could insert:

# Type 'tw' on the terminal to open TextWrangler
alias tw='open -a /Applications/TextWrangler.app'

To make TextWrangler the default:

  1. "Get Info" on a text file in the Finder.
  2. Change the "Open with:" program to TextWrangler, in the fifth information pane.
  3. Click the "Change All..." button at the bottom of the pane.

If you have the TextWrangler command line tools installed, you can just type

edit my_text_file.txt

in the terminal and it should open.

If this doesn't work you have to install the TextWrangler command line tools.

If you installed the MacApp store version, download the installer from this page: http://www.barebones.com/support/textwrangler/cmd-line-tools.html

If you downloaded from the BareBones Software site, there should be an "install command line tools" command in either the Application (TextWrangler) menu or the help menu. I think it's in the Text Wrangler menu.


IMO, using open is the correct approach. However it requires a bit of typing, so you may want to consider creating a shell alias for it. This approach is also good if you don't want to change your default editors.

$ alias tw='open -a /Applications/TextWrangler.app'
$ tw myfile.txt

To have the alias available in every shell you open, just add the line to .bashrc in your home directory. If you don't have a .bashrc yet, just create it yourself and add the line. Then open a new terminal tab to try it out.