Default editor for files without file name extension in Mac OS X

25

29

I want to open files without file name extension, including .dotsystemfiles (e.g. .htaccess or .vimrc) with a different editor than TextEdit. Doing the regular Change All... in the Get Info panel won't do the trick as it gives the following error:

alt text

jasonkuhrt

Posted 2011-01-11T17:09:35.317

Reputation: 253

Answers

26

You need to change the editor for the text/plain mime type or public.plain-text UTI. The regular Get Info dialog changes the association for the file name extension, which these files don't have.


Get RCDefaultApp and install it.

Open System Preferences » Default Apps » Apps. Select your desired default editor, and look for either of the above in the application's list of supported types.

alt text alt text alt text

Select the entry, and click Set as Default. You're done. Both opening from Finder and the command-line open will open your new default editor.


This also changes all .txt files and the like. I don't think this can be prevented, since OS X thinks both these and extension-less files are public.plain-text/text/plain.


To do this without RCDefaultApp, edit Edit ~/Library/Preferences/com.apple.LaunchServices.plist.

Add an entry under LSHandlers, containing the UTI (key LSHandlerContentType, e.g. public.plain-text) and application bundle identifier (LSHandlerRoleAll, e.g. com.macromates.textmate).

It looks like this in Property List Editor:

alt text alt text

Daniel Beck

Posted 2011-01-11T17:09:35.317

Reputation: 98 421

To set MacVim as the default, use "org.vim.macvim" for "LSHandlerRoleAll". – Eric Hu – 2016-05-09T11:43:29.627

This does not work in macOS Mojave or higher. Can you please suggest what we do now? Thanks. – Nanashi No Gombe – 2019-10-31T14:23:43.673

1Or choose the Mime types tab and choose what app text/plain is opened by (this allows Aquamacs.app to be used which does not have the Mime types shown in its list – user151019 – 2011-01-11T18:18:10.290

This worked for me. Thanks a lot Daniel. A couple things to add: I needed to log out of the OS and then back in. Also, curiously, .DS_STORE files still open in TextEdit by default, but all other .dotsystemfiles are now opening in my desired editor. – jasonkuhrt – 2011-01-11T19:57:21.117

Is there a way to do this with defaults write instead of downloading third party software? – ma11hew28 – 2011-01-20T05:29:52.497

@Matt See my edited post. – Daniel Beck – 2011-01-20T06:14:29.047

What's the difference between text/plain and public.plain-text? Is there any reason other then @Mark's example to choose one over the other? – Orion751 – 2011-08-14T02:13:00.343

@Orion One is a MIME type, the other is a Uniform Type Identifier. Just a different format to describe other document formats. They're usually easily interchangeable, which is why my answer contains both, except in cases like Mark's.

– Daniel Beck – 2011-08-14T10:01:12.517

2

You can also run plutil -convert xml1 ~/Library/Preferences/com.apple.LaunchServices.plist and add something like this:

<dict>
    <key>LSHandlerContentType</key>
    <string>public.plain-text</string>
    <key>LSHandlerRoleAll</key>
    <string>com.macromates.textmate</string>
</dict>
<dict>
    <key>LSHandlerContentType</key>
    <string>public.unix-executable</string>
    <key>LSHandlerRoleAll</key>
    <string>com.macromates.textmate</string>
</dict>

You can apply changes by restarting or by rebuilding the Launch Services database. Logging out and back in isn't enough.

Or add this to a duti configuration file:

com.macromates.textmate public.plain-text all
com.macromates.textmate public.unix-executable all

public.plain-text also includes files with a .txt or .text extension. I don't know any way to change the default application for files with arbitrary extensions.

public.unix-exexutable includes executable scripts without a filename extension. If you try to change the default application for them from Finder, there is an error like this:

The operation can’t be completed.

An unexpected error occurred (error code -50).

Lri

Posted 2011-01-11T17:09:35.317

Reputation: 34 501