Using duti to configure the default applications for file types

See http://duti.org/documentation.html or https://github.com/moretension/duti for documentation.

You can install duti by running brew install duti.

My duti configuration file

# .txt, .text, and plain text files without an extension
org.gnu.Emacs public.plain-text all

# executable scripts
org.gnu.Emacs public.unix-executable all

com.SequentialX.Sequential .jpg all
com.SequentialX.Sequential .png all
com.movist.Movist .3gp all
com.movist.Movist .avi all
com.movist.Movist .flac all
com.movist.Movist .flv all
com.movist.Movist .m4v all
com.movist.Movist .mkv all
com.movist.Movist .mov all
com.movist.Movist .mp4 all
com.movist.Movist .mpg all
com.movist.Movist .wmv all
com.robinlu.iChm .chm all
cx.c3.theunarchiver .rar all
net.sourceforge.skim-app.skim .pdf all
net.sourceforge.skim-app.skim .ps all
org.gnu.Emacs .as all
org.gnu.Emacs .aslquery all
org.gnu.Emacs .ass all
org.gnu.Emacs .bash all
org.gnu.Emacs .bom all
org.gnu.Emacs .c all
org.gnu.Emacs .cfm all
org.gnu.Emacs .cfml all
org.gnu.Emacs .class all
org.gnu.Emacs .conf all
org.gnu.Emacs .cpp all
org.gnu.Emacs .css all
org.gnu.Emacs .csv all
org.gnu.Emacs .ctp all
org.gnu.Emacs .dat all
org.gnu.Emacs .data all
org.gnu.Emacs .dict all
org.gnu.Emacs .doc all
org.gnu.Emacs .el all
org.gnu.Emacs .h all
org.gnu.Emacs .java all
org.gnu.Emacs .js all
org.gnu.Emacs .json all
org.gnu.Emacs .less all
org.gnu.Emacs .log all
org.gnu.Emacs .m all
org.gnu.Emacs .manifest all
org.gnu.Emacs .md all
org.gnu.Emacs .mm all
org.gnu.Emacs .nfo all
org.gnu.Emacs .opml all
org.gnu.Emacs .org all
org.gnu.Emacs .pg all
org.gnu.Emacs .php all
org.gnu.Emacs .pl all
org.gnu.Emacs .plist all
org.gnu.Emacs .py all
org.gnu.Emacs .rb all
org.gnu.Emacs .rd all
org.gnu.Emacs .readme all
org.gnu.Emacs .rst all
org.gnu.Emacs .sb all
org.gnu.Emacs .scss all
org.gnu.Emacs .sh all
org.gnu.Emacs .srt all
org.gnu.Emacs .strings all
org.gnu.Emacs .sub all
org.gnu.Emacs .tex all
org.gnu.Emacs .tsv all
org.gnu.Emacs .utf all
org.gnu.Emacs .xml all
org.gnu.Emacs .yaml all

You can usually specify file types using filename extensions instead of UTIs. duti converts filename extensions (like .jpg) to UTIs (like public.jpeg) that also apply to other filename extensions (like .jpeg). Try to look at ~/Library/Preferences/com.apple.LaunchServices.plist after running duti. For some extensions like .mkv and .tex, the UTI depends on what application registered the extension first.

Applying changes to a duti configuration file automatically

Save a property list like the one below as ~/Library/LaunchAgents/duti.plist and run launchctl load ~/Library/LaunchAgents/duti.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>EnableGlobbing</key>
  <true/>
  <key>Label</key>
  <string>duti</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/duti</string>
    <string>~/.duti</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>~/.duti</string>
  </array>
</dict>
</plist>

EnableGlobbing is only used to enable tilde expansion for ProgramArguments. (Tilde expansion is enabled by default in WatchPaths.)

Listing the filename extensions supported by an application

This lists the filename extensions of the file types supported by an application whose Info.plist includes CFBundleTypeExtensions arrays:

plutil -convert json /Applications/Safari.app/Contents/Info.plist -o -|jq -r '.CFBundleDocumentTypes[].CFBundleTypeExtensions[]'

This lists the filename extensions of the file types supported by an application whose Info.plist does not include CFBundleTypeExtensions arrays:

x=$(/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump)
plutil -convert json /Applications/TextEdit.app/Contents/Info.plist -o -|jq -r '.CFBundleDocumentTypes[].LSItemContentTypes[]'|
while read l;do
  awk "/uti: *$l/,/tags:/"<<<"$x"
done|sed -n 's/[[:blank:]]*tags: *\(.*\)/\1/p'|sed $'s/, /\\\n/g'|grep ^\\.|sort -u