6

File with no extension will be opened by TextEdit by default. For example, in terminal run open ~/.ssh/known_hosts will open TextEdit to edit known_hosts

These files are normally just text file so I don't want to use TextEdit open them (e.g. I want to use BBEdit to open them) but because they have no extension I can't find an each way to change the default app to open them in one shot. Change them one by one is not workable.

So is there any way to change them in one shot?

Replace Text Edit as the default text editor does not work for me,

First, the highest two answers there said something like duti -s com.sublimetext.4 public.plain-text all but as @Seamus said in his updated answer "The accepted answer may have been correct when it was written, but does not work for current (as of approximately Catalina vintage) systems because the UTI for a text file without a file extension is now apparently public.data". Besides I don't know how edit bbedit part, is it com.bbedit.13 (I use bbedit 13 or what else)?

Second, all the other 3rd-party apps are too old, at least 10 years old without any update.

1
  • 1
    Any unresolved aspects of this question? ICYI, I found a lot of useful information for further research from these sources: 1; 2; 3; 4 Commented Apr 30, 2023 at 0:52

3 Answers 3

3

This is one way to do it. Note that I've done limited testing of this on my macOS Ventura system - YMMV.

One Approach:

In Terminal.app enter the following command:

% defaults write ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist LSHandlers -array-add '{LSHandlerContentType=public.data;LSHandlerRoleAll=com.barebones.bbedit;}' 

You will need to re-start your machine afterwards for this to take effect.

Alternatively, you may edit the file ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist to add the following as the last <dict> element in the plist:

 . .. ... <dict> <key>LSHandlerContentType</key> <string>public.data</string> <key>LSHandlerRoleAll</key> <string>com.barebones.bbedit</string> </dict> </array> </dict> </plist> 
11
  • "Other answers depend on 3rd-party apps which are either obsolete or ill-maintained." A Swift one: github.com/Lord-Kamina/SwiftDefaultApps Commented Apr 28, 2023 at 23:42
  • 1
    Is restarting the only way? Commented Mar 23, 2024 at 14:12
  • @Andy: good question. Based on similar usages of defaults you may have a couple of alternatives to a re-start: 1) log out & logon; 2) run killall Finder from the Terminal. Commented Mar 23, 2024 at 18:50
  • I tried log out/on and relaunching Finder&Dock - no luck Commented Mar 23, 2024 at 20:04
  • @Andy: Have you tried a re-start? Sorry - it's been almost a year since this was posted. I do try hard to test everything I put in an answer, so it's also possible that a re-start was the only way I found to make it persistent. ALSO: Just checked my system, and learned the file has been changed to a binary file in one of Apple's updates. Consequently, it is also possible that this no longer works! Commented Mar 23, 2024 at 20:43
1

The modern replacement for RCDefaultApp (the ancient prefs pane you're presumably referring to) is "SwiftDefaultApps"

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

For text files, you need to set the handlers for public.plain-text and public.data (the latter necessary for files with no extension, which are opened by default with TextEdit - yuck)

0

Works for Mac OS Sequoia 15.4.1 on Apple Silicon

duti is a utility to set default file types

> brew install duti 

get the app which currently opens plain text files with a .txt extension

> duti -d public.plain-text org.vim.MacVim 

set the app which opens plain text files without an extension

> duti -s org.vim.MacVim public.data all 

Bonus Points: there is an app called PreviewText on the App Store which can give your extensionless text files a QuickLook preview. 🙏

1
  • Doesn't the question mention that using duti ... all doesn't help? Has this changed again with recent versions of macOS? Commented Apr 22 at 15:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.