13

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
  • Did you ever get a real answer to this? Nov 4, 2021 at 12:20
  • 1
    No, still haven't solved it. But to open text files from Terminal I now just type sublime ~/.bash instead of open ~/.bash
    – Rachid
    Nov 4, 2021 at 20:29
  • On my Ventura system, I've found that plaintext files that have no extensions, and are not designated as executable are no longer classified with UTI public.plain-text. Rather they are now designated as public.data. See this answer
    – Seamus
    Apr 29 at 0:33

4 Answers 4

8

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, 2021 at 22:33
2

I had the same problem on Big Sur 11.6.1 - Intel

I think it's due to mixed entries in ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

So I had previous sublime entries inside of it and I think that were the confusion was coming from.

I've checked the CFBundleIdentifier inside of the

/Applications/Sublime Text.app/Contents/Info.plist

In my case it says it's com.sublimetext.4 (depends on the version of the sublime you have installed.)

In my case I have been already using Sublime for some longer time with previous releases and also with previous MacOS releases.

This is what I did:

  1. Removed the ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
  2. Restart MacOS so the system recreates com.apple.launchservices.secure.plist
  3. As the current logged in user executed
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add  '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.4;}'
  1. Restart MacOS
  2. Voalá, everything plain-text based is now being opened in sublime.
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
  • That repository hasn't been updated for over 10 years. Oct 9, 2021 at 9:13
-2

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
    Feb 5, 2021 at 17:31
  • sure it does. Click on a file in finder without an extension and complete the process.
    – Natsfan
    Feb 5, 2021 at 23:59
  • 1
    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, 2021 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
    Feb 6, 2021 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, 2021 at 1:18

You must log in to answer this question.

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