How to open a text file with TextWrangler from the Terminal (command line)

terminaltext-editor

Often when I work in the Terminal (the command line) I need to edit some text files. I prefer to edit text files using TextWrangler.

How can I open a text file with TextWrangler from the Terminal?

I tried with /Applications/TextWrangler.app/ my_text_file.txt but it doesn't work since TextWrangler.app/ is a directory.

Best Answer

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.