Set SublimText 3 as default app for files without extension [duplicate]

Files without extension always open in TextEdit ... I want them to open in SublimText 3

I tried to change my com.apple.launchservices.secure.plist, but simply adding public.text did not work ...


The solution was doing it with public.data

  1. Go to ~/Library/Preferences/com.apple.LaunchServices

  2. Open com.apple.launchservices.secure.plist with Xcode

  3. Add this :

screen

  1. Save & Reboot

Another way to do it

  • Without Xcode
  • Working on macOS Mojave
  • With Sublime Text 4
  1. Convert binary plist to xml plist (for easy editing)
plutil \
-convert xml1 \
~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist \
-o ~/Desktop/plist.xml
  1. Open plist.xml (on your Desktop) with Sublime Text

Add inside <array>

<dict>
    <key>LSHandlerContentType</key>
    <string>public.data</string>
    <key>LSHandlerPreferredVersions</key>
    <dict>
        <key>LSHandlerRoleAll</key>
        <string>-</string>
    </dict>
    <key>LSHandlerRoleAll</key>
    <string>com.sublimetext.4</string>
</dict>
  1. Convert back from XML to binary plist
plutil \
-convert binary1 \
~/Desktop/plist.xml \
-o ~/Desktop/com.apple.launchservices.secure.plist
  1. Move the new com.apple.launchservices.secure.plist, from your Desktop to ~/Library/Preferences/com.apple.LaunchServices/
mv ~/Desktop/com.apple.launchservices.secure.plist \
~/Library/Preferences/com.apple.LaunchServices/
  1. Reboot

You can also use Sublime package Plist Binary or BinaryPlist instead of manually converting from binary to XML


Copy paste script (working with 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.