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.


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;}'

  • Do you know how to read the current value with defauls also? 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. 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

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.

  • 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 '14 at 18: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.

  • 1
    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! Feb 16 '14 at 4:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .