Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 Answers

up vote 22 down vote accepted

As a one-time thing,

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

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.
share|improve this answer
    
After making it the default, then you use open file.txt. –  user588 Mar 4 '11 at 20:42
6  
You can leave out the path to the application completely, as open consults the LaunchServices DB. So open -a TextWrangler file.txt is enough. –  Asmus Mar 5 '11 at 10:27
    
when you say "as a one-time thing", do you mean you only have to do it one time (and after that the prefs are saved), or do you mean it only applies one time (and after that you have to do it again to achieve the same result)? –  chharvey Mar 26 at 4:55
add comment

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 at the bottom of the page http://www.barebones.com/store/macappstore.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.

share|improve this answer
    
I just tried and installed TextWrangler, first time I open it asks for "installing command line tools" and voia-lah. –  Cawas May 2 '13 at 11:39
    
@Peter, i wish i could give you a bounty for this! been trying to set textwrangler as my default git editor –  Brad Jan 7 at 19:38
add comment

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.

share|improve this answer
add comment

If you have the TextWrangler command line tools installed you can use 'edit' to open files in TextWrangler from the command line. You should have been prompted at the initial install to install the tools, or you can go to the preferences and the "Tools" section and click the installer button. It also gives you twdiff, a TextWrangler-based diff tool. You can 'man edit' if the tools are installed to see all the switches available.

share|improve this answer
add comment

Your Answer

 
discard

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.