58

How can I set TextMate as default text editor on Mac OS X?

I've tried it with

ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate
export EDITOR='mate -w'

but that doesn't work.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Ben
  • 741
  • 1
  • 7
  • 14
  • See also [Change the default application (for a file extension) via script/command line?](http://apple.stackexchange.com/questions/49532/change-the-default-application-for-a-file-extension-via-script-command-line/) and [How to permanently put TextEdit in the Open with… menu list?](http://apple.stackexchange.com/questions/60591/how-to-permanently-put-textedit-in-the-open-with-menu-list/). – Piotr Migdal Jan 31 '13 at 16:12
  • I find this post easy and useful http://www.imore.com/how-change-default-apps-os-x – shellbye Jun 03 '16 at 03:38

7 Answers7

93

Just right (or control) click a file of the type you want to change and:

"Get Info" -> "Open with:" -> (Select TextMate) -> "Change All"

Timeout
  • 7,489
  • 24
  • 37
  • 11
    keep in mind, this will be on a per file extension basis, so you will have to do it for a file of each file extension you want textmate to be the default editor for. – rick Feb 21 '12 at 04:09
  • 2
    Correct, I've done this for Sublime editor. Sweeping changes make me a bit nervous that it will go way too far (good luck rolling back) and there's really only a handful of file types that need altering. I do them on an as needed basis. – Timeout Feb 21 '12 at 04:18
  • 1
    Hi,I do as you said,but only work for one file,not for all of them. – Ben Feb 22 '12 at 00:25
  • 1
    @Ben After selecting TextMate from the drop down you must hit the "Change All..." button and confirm. It most definitely works, as I said I do this myself. – Timeout Feb 22 '12 at 02:17
  • no, it's not working for all file as I said only for one file..I dont know why. – Ben Feb 24 '12 at 22:44
  • 7
    @Ben you need to make sure and actually right click > Get Info, and look for 'Open with:' in that Info view. This is different then right clicking and doing 'Open With' right from that first menu. I initially made this mistake and it changed only that one file. – dizy Oct 02 '12 at 04:19
43

The method through Finder is not practical. If you're a developer, your files likely include .profile, .gitconfig, .bashrc, .bash_profile, .htdocs, etc.

The best way to do this is in Bash (for Sublime Text 3):

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

For other text editors, I assume you can replace 'com.sublimetext.3' with the proper string. You could probably Google for your text editor's name + "LSHandlerContentType=public.plain-text" to figure out what your app's string would be.

For me, this changed the defaults for both Finder, and

$ open ~/.bashrc
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
KFunk
  • 2,541
  • 20
  • 30
  • 10
    Most of us only use one text editor at a time. Finder changes the default for a given filetype, but who wants to change it for .html, .htm, .sh, .py, .txt, .css, .conf, .prod-conf, .staging-conf, .dev-conf (or whatever other developers on a team might call certain configuration files), .md, .gitconfig........ the list is endless. TextEdit is a HORRIBLE text editor. Sweeping changes are good when it replaces that **CRAP** software that defaults to rich text, which may break something if you open/save with it because you haven't yet marked this filetype using Finder. – KFunk Mar 15 '14 at 21:49
  • 1
    By the way, what if I switch my text editor from SublimeText2 to SublimeText3 (they removed version number on the app name finally)? Or my machine craps itself and I have to reinstall the OS? Go through every filetype in finder? Not practical unless you live in a perfect world. – KFunk Mar 15 '14 at 21:52
  • 7
    This is the specific answer I was looking for, since I was trying to set the default editor for dotfiles that contain preferences. Thank you. – Brian Kung Mar 31 '14 at 19:50
  • 12
    For other editors the string can be found in the app's `Info.plist`. Right click the app in question -> show package contents -> open `Contents`-> open `Info.plist` with a text-editor -> locate the key `CFBundleIdentifier`-> the string value below is the string in question. – thee Aug 19 '14 at 22:06
  • 3
    `Info.plist` for Textmate 2 is `CFBundleIdentifier = com.macromates.TextMate.preview";` but that didn't seem to work for me – Chris Beck May 28 '15 at 20:50
  • I found that (at least on el capitan), the plist is in a subfolder, which isn't modified by the before mentioned `defaults write...`, open `~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist` to add the handler manually. – Koen. May 18 '16 at 19:29
  • Or use `defaults write com.apple.LaunchServices/com.apple.launchservices.secure ...` – Koen. May 18 '16 at 19:32
  • FYI, the identifier for Atom appears to be `com.github.atom` on my machine. – Ryan Walls Jul 08 '16 at 21:51
  • in which file can I find the setting for the textmate to be set by default? – Rishikesh Shukla Mar 18 '17 at 20:02
  • 2
    this doesn't work on mac-os sierra. for me "open .bash_profile" is still opened by textmate :( – Rishikesh Shukla Mar 18 '17 at 20:06
2

This worked for me on OS X v10.11 (El Capitan):

defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.textmate.preview;}'
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
SteveCoffman
  • 813
  • 1
  • 7
  • 20
2

For TextMate 2:

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

And you need to restart after that.

Anton Plebanovich
  • 1,122
  • 15
  • 15
2

Have you modified your shell PATH environment variable to include ~/bin? That directory is usually not included in PATH by default on OS X. It might be simpler to create the symlink in /usr/local/bin which is usually included in PATH. Try:

echo $PATH
Ned Deily
  • 81,219
  • 16
  • 124
  • 150
1

To change the default text editor across the board, use the aforementioned method (i.e., "Get Info" → "Open with:" → (editor of choice) → "Change All") on .txt files. Then it will be used as the default editor for any text-based file that doesn't yet have an application preference for its extension.

For instance, if you use the terminal, the command open -t will use your preferred text editor, which is whatever application is associated with .txt files. By default this is (you guessed it) TextEdit, unless you explicitly specify otherwise.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
eestrada
  • 1,475
  • 14
  • 22
0

I found Replace Text Edit as the default text editor on apple.stackexchange which works really well.

For developer-type files like .gitignore, use the last option provided:

duti -s com.macromates.TextMate public.data all

Substitute your editor's CFBundleIdentifier as needed. To find it, locate the application file, right-click and choose Show Package Contents, then open Info.plist in the Contents folder. CFBundleIdentifier should be near the top...

This work on Catalina. I'll update my answer if/when I update my OS.

randy
  • 183
  • 1
  • 11