4

I just never want TextEdit to be opened, and instead set sublime as the default editor for all plain-text files. So not only files with *.txt extension.

For older versions than Big Sur the following command always has worked for me:

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

From this answer: https://apple.stackexchange.com/a/123834/405588

But on Big Sur this doesn't work anymore. Even after restarting MacOS text files still open with TextEdit.

edit: apparently after running the command above double clicking dot files like ~/.bashrc do open in Sublime. But when running open ~/.bashrc from Terminal it still opens the file in TextEdit...

3

Have you tried SwiftDefaultApps? It's a modern replacement for the old RCDefaults System Preferences pane.

https://github.com/Lord-Kamina/SwiftDefaultApps

Here are two screen shots of SwiftDefaultApps, the first showing Uniform Type Identifiers tab for public.plain.text with Sublime Text 2 set as the Editor, and the second showing the Applications tab and Sublime Text 2 with public.plain.text checked. (This works the same with Sublime Text 3 too.)

With these settings, any plain text file, with or without a .txt extension, will open in Sublime Text when double-clicked in Finder.

SwiftDefaultApps - Uniform Type Identifiers tab for public.plain.text

SwiftDefaultApps - Applications tab for public.plain.text


Historical Reference: RCDefaultApp @ web.archive.org: https://web.archive.org/web/20200312011847/http://www.rubicode.com/Software/RCDefaultApp/

1
  • No, I didn't try that. At first I thought that if it's possible with installing that UI, it should also be possible without installing an additional program. But I tried it now and the settings were already the same as in your screen shot. And when double clicking for example "~/.bashrc" in Finder it opens with Sublime. Only when running "open ~/.bashrc" it still opens with TextEdit. So maybe the old command did work for Finder, but not for the "open" command from Terminal... – Rachid Feb 6 at 22:33
0

Now I also found a solution for opening text files from Terminal, like open ~/.bashrc. This answer finally helped. What I needed to do is the following:

brew install duti

Associate files of the kind 'public.data' with sublime as well:

duti -s com.sublimetext.3 public.data all

While I still would prefer to achieve such changes without the need to install additional tools the problem is now solved for me. But if anyone knows a way to achieve the same without installing duti please let me know.

-1

From Finder, you can click on a .txt, .rtf, .text, or other text file extensions and press "command-i" keys. This is for get info. You get a new pane that looks like image below.

enter image description here

Towards the bottom you'll see a line that says 'Open With". Under that is a text box with "TextEdit" in it. That tells the computer to open .txt files with TextEdit. Click on the textbox and you'll see a list of applications. Choose Sublime Text from the pulldown menu and close the box. Under that is the phrase "Change All". Click on this. Now all .txt files will open with sublime.

Repeat this process for other files types you wish to open with Sublime. Sorry there is not a single switch.

5
  • 2
    This doesn't work for files without an extension – Ezekiel Elin Feb 5 at 17:31
  • sure it does. Click on a file in finder without an extension and complete the process. – Natsfan Feb 5 at 23:59
  • Thnx for that tip, but this is not what I'm searching for. Then I need to configure it for every possible extension. Especially for opening random dot files from the Terminal this is not workable... And before Big Sur there was a single switch (for all files of kind: text) and I can't believe it is not possible anymore in Big Sur... – Rachid Feb 6 at 22:02
  • 1
    @jmh Please try it before saying it works - if it doesn't have an extension you can't register it globally, only for the single file i.imgur.com/SSNqWnP.png – Ezekiel Elin Feb 6 at 22:12
  • You are assuming all files without an extension are the same. I've got many files without an extension that opens in Coderunner and they are set to coderunner. But I do get an error message when trying to save the default for the file but i assumed it worked anyway since different files were opened with different apps. – Natsfan Feb 7 at 1:18

You must log in to answer this question.

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