Apple - Replace Text Edit as the default text editor
Another option is to use duti (https://github.com/moretension/duti).
Run brew install duti
, save a filetype like this as:
duti -s com.sublimetext.3 public.plain-text all
The changes should be applied immediately, so you don't have to restart like when editing com.apple.LaunchServices.plist
.
To also change the default application for executable scripts with no filename extension, add a line like this:
duti -s com.sublimetext.3 public.unix-executable all
Some files are also considered 'public.data', not 'public.plain-text', so you can do this as well:
duti -s com.sublimetext.3 public.data all
To set Sublime Text as the default handler for public.plain-text:
Mavericks (10.9) and earlier
defaults write com.apple.LaunchServices \
LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
Yosemite (10.10) and later
Use com.apple.LaunchServices/com.apple.launchservices.secure.
defaults write com.apple.LaunchServices/com.apple.launchservices.secure \
LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
Remember to restart to pick up the changes.
I tried grg's solution in the past and I believe it worked. However, on Yosemite and El Capitan, I ran into problems.
DonnaLea's comment in that solution clued me in on creating a solution. I added the folder path before com.apple.launchservices
additionally the file had a slightly different name com.apple.launchservices.secure
.
You can see the file/folders being modified in the following path:
/user/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
Screenshot for reference: [![enter image description here][1]][1]
Here's the command I used in terminal:
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
Lastly, after a restart to my machine it worked as advertised. [1]: http://i.stack.imgur.com/qQOQg.jpg