I always found it super irritating that MacOS makes setting up default file associations such a manual process. Then I discovered duti
duti
is a command-line utility that allows you to define the default file opener for any file type. You can set your favorite text editor to open code files, have PDFs open in your preferred viewer, and assign specific applications to open different image file types.
Getting Started with Duti
Before using duti
, you need to install it. The simplest way to install duti
on your Mac is via Homebrew. If you haven't installed Homebrew yet, you can install it with this command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, you can install duti
with the following command:
brew install duti
Using Duti to Set Default Applications
The basic syntax of the duti
command is:
duti -s com.example.MyApp myextension all
Here, com.example.MyApp
is the bundle identifier of the application you want to set as the default, myextension
is the file extension you want to change the default for, and all
is the role (which can be 'all', 'editor', or 'viewer').
To find the bundle identifier of an application, you can use the following command, replacing AppName
with the name of the application:
osascript -e 'id of app "AppName"'
For example, to set Visual Studio Code as the default application for .txt files, you would first get Visual Studio Code's bundle identifier:
osascript -e 'id of app "Visual Studio Code"'
This will output something like com.microsoft.VSCode
. You can then set Visual Studio Code as the default for .txt files with:
duti -s com.microsoft.VSCode txt all
Verifying Changes with Duti
To verify your changes, you can use the -x
flag followed by the extension:
duti -x txt
This should return something like this:
/Volumes/Macintosh HD/Applications/Visual Studio Code.app
com.microsoft.VSCode
This confirms that Visual Studio Code is now the default application for .txt files.
Top comments (0)