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.

OSX seem to offer open -t command line shortcut to open arbitrary files in the system default text editor.

  • Where is this default text editor set?

  • Can I change it from the command line (if possible) or otherwise programmatically?

The default choice of TextEdit is limiting.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

It's the default application for plain text (public.plain-text) files. You can change it from Finder's information panels or with duti.

You can also edit ~/Library/Preferences/com.apple.launchservices.plist, but it requires restarting to apply the changes.

defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.textmate;}'

share|improve this answer
    
Do you know how to read the current value with defauls also? –  Mikko Ohtamaa Dec 4 '12 at 23:08
    
@MikkoOhtamaa man defaults will tell you how to do that, but basically defaults read com.apple.LaunchServices LSHandlers will tell you the default handler for all the file types. –  Smilin Brian Dec 11 '12 at 22:49
    
Default applications changed from Finder aren't added to com.apple.LaunchServices.plist. You can use lsregister -dump or DefaultApplication. (Or duti if you're just trying to avoid adding two entries to the plist.) –  Lri Dec 13 '12 at 7:26

According to the open(1) man page:

-t Causes the file to be opened with the default text editor, as determined via LaunchServices

  1. To change the associated editor, find a file with the extension you are trying to open in the Finder and select it.
  2. Select File > Get Info from the menu bar.
  3. Change the "Open With" to your text editor of choice.
  4. Press the "Change All…"

Now your files with that extension should open in your selected text editor with "open -t " from the command line.

share|improve this answer
    
Didn't work for me. –  JohnK Sep 10 '13 at 15:53
    
^ it works perfectly instead of changing the default through command line! Thank you! –  Ting Ting Lei Feb 16 at 4:58

You can also use open -a <application> <file> to open a file from the Terminal in the editor of your choice, like so:

open -a TextWrangler.app myfile.txt

To make this a bit shorter, I also have an alias in my .profile file, like so:

alias edit="open -a TextWrangler.app $1"

This allows me to just type:

edit myfile.txt

and the file will open in TextWrangler.

share|improve this answer
    
Just a heads up, you can also achieve this by running "Install Command Line Tools" from TextWrangler's application menu. It'll install an edit command, which does what your alias does, and in addition has a bunch of command line options. –  duozmo Feb 11 at 18:26

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.