Change the default application (for a file extension) via script/command line

applescriptcommand linedefaults

Is there a way to define the default application for a file extension via an Apple script, command line command (like defaults write [...]).

I know that you can change it manually via the information panel or by using RCDefaultApp but as I have to setup many machines and user accounts I would like to find a way to automate the process.

Best Answer

duti is a shell utility that enables using a text file to configure the default applications for file types and URL schemes.

For example save a file like this as ~/.duti:

com.gnu.Emacs public.plain-text all 
com.gnu.Emacs public.unix-executable all
org.videolan.vlc .mkv all

Then run duti ~/.duti.

You can install duti with brew install duti or by running wget https://github.com/fitterhappier/duti/archive/duti-1.5.2.tar.gz;tar -xf duti-1.5.2.tar.gz;cd duti-duti-1.5.2;./configure;make;sudo make install.