38

Is it possible to set a default application to open files with no extension? I'm not referring to files with hidden extensions, but those completely lacking an extension -- e.g. README, CHANGELOG, mbox, etc.

Open With > Change All on these files doesn't work, returning the error shown below:

Screenshot of a dialog box containing 'An error occurred while changing the application that opens "mbox" because not enough information is available. Do you want to open "mbox" with "TextEdit.app"?'

Ideally, I would like the system to try opening all such files in TextMate. I know I can drag files onto Dock icons to open them in specific apps, but I'm looking for a more seamless solution than that (especially since I have my Dock auto-hide, which makes it much more cumbersome).

I am familiar with the QLStephen QuickLook plugin that can enable QuickLook for some of these files, but I would prefer a solution with selecting/copying/editing capabilities.

5 Answers 5

20

You can add a default application for public.plain-text in ~/Library/Preferences/com.apple.LaunchServices.plist.

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

Restart to apply the changes (logging out and back in isn't enough).

I've added this to a duti configuration file:

com.apple.textedit public.plain-text all
com.macromates.textmate public.unix-executable all
4
  • 10
    This looks like a good one, more details of what is going on here at a top-level would be nice. An intro, what is going on in step 1, etc.
    – MrDaniel
    Commented Aug 13, 2012 at 19:22
  • In case anyone would like to use Visual Studio Code as the default editor, use com.microsoft.VSCode instead of com.apple.textedit in the answer above. Or, for Sublime Text 4, use com.sublimetext.4. Commented Oct 19, 2022 at 3:17
  • 1
    This answer may have been true & correct when it was published almost 11 years go, but (probably due to Apple's changes) is no longer correct. There is an updated answer to a similar question here.
    – Seamus
    Commented Apr 28, 2023 at 23:30
  • 1
    This duti configuration worked for me: com.microsoft.VSCode public.data all Commented Aug 3, 2023 at 10:08
5

You can do this using Magic Launch. After installing, you can create rules to launch based on various criteria. You need to create a rule for text apps where the extension is blank. You can set up more complex logic if you need it.

http://michelf.com/software/magic-launch/

4
  • You're right -- I had to create a custom rule to handle files with blank extensions...but it seems to have worked -- thanks! The only downside is that it's $13. I have no problem paying for good apps, but that's a bit steep considering I'm looking for just this one feature.
    – Austin
    Commented May 7, 2011 at 4:07
  • the url is not found Commented Dec 1, 2020 at 7:37
  • let me google it for you: oneperiodic.com/products/magiclaunch
    – apollo
    Commented Jan 2, 2021 at 10:46
  • Is still not found... this is an obsolete answer because it's a recommendation for an obsolete product.
    – Seamus
    Commented Apr 28, 2023 at 23:33
3

Update for Catalina:

defaults write ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}' '{LSHandlerContentType=public.unix-executable;LSHandlerRoleAll=com.sublimetext.3;}'

This sets the default to Sublime Text 3. If you want to have any other app you have to simply replace com.sublimetext.3 with the app id of your favorite app.

1
  • 2
    tried it but it didnt work on Catalina 10.15.6 and sublime 3.2.2 how did u know that com.sublimetext.3 is correct? Commented Dec 1, 2020 at 7:36
1

Take a look at RCDefaultApp (freeware).

RCDefaultApp is a Mac OS X 10.2 or higher preference pane that allows a user to set the default application used for various URL schemes, file extensions, file types, MIME types, and Uniform Type Identifiers (or UTIs; MacOS 10.4 only).

1
  • 2
    I like that it's free, but there's no way to set a default app for files with no extension. Using MIME types can approximate this somewhat, but then it changes the default app of all text files, not just those with no extension. Thanks for the suggestion anyway -- perhaps it will help someone else.
    – Austin
    Commented May 7, 2011 at 4:07
1

A bit late this, the question "How to avoid typeless files opening in terminal" being a bit old. However:

The solutions above involve changing the existing rules, which can have unwanted side-effects. I find the easiest is to exploit the existing rules for typeless files and changing file permissions to get the result I want.

Specifically: Switch off the executable bit on the file, because that's what's telling file service to open with terminal with "chmod -x filename" where filename is ... the filename.

This can be automated to some extent (with caution): In my case, I have a lot of README files on a machine. I can use "find" to find all "README" files. And then use "awk" to construct a command to remove the executable bit on all of them as follows:

find /$HOME -iname 'README' | awk '{ print "chmod -x " $0 }'

type that into the terminal if you want to check what files will be changed: The output will consist of a listing for each README found looking something like this:

chmod -x //Users/jimpsmith/things/README

And to change all those permissions execute all these lines by feeing them to bash as follows:

find /$HOME -iname 'README' | awk '{ print "chmod -x " $0 }' | bash

Just beware of using wildcards too liberally and finding you're accidentally removed the executable bit from some executables that erroneously match.


An easier way would be to just run

find /$HOME -iname 'README' -exec chmod -x '{}' \;`

or (to see what would happen)

find /$HOME -iname 'README' -exec echo chmod -x '{}' \;`
1
  • 5
    I somehow fail to understand how this solves the problem stated in the question. README, ChangeLog etc. usually don't have the x bit set to start with anyway. The problem is that OS X relies on suffixes to identify the application to open file with and these files don't have a suffix.
    – nohillside
    Commented Dec 1, 2012 at 14:24

You must log in to answer this question.

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