How to Set Default Applications for File Types in macOS Terminal Using duti

In macOS, assigning default applications for specific file formats is typically handled through Finder’s graphical interface: right-clicking a file, selecting “Get Info,” choosing an application from the “Open with” menu, and clicking “Change All…”. While effective for individual users managing a single file extension, this manual workflow is slow and cannot be scripted across enterprise Mac fleets or automated developer workstation setups.

The duti (default update text interface) command-line tool provides a fast, scriptable method to query, set, and bulk-configure default application handlers for file extensions, Uniform Type Identifiers (UTIs), and URL schemes in macOS Terminal.

Installing duti on macOS

The duti utility is maintained as an open-source project and is readily installable via Homebrew:

brew install duti

Verify that the binary is available in your shell path:

duti -V

Discovering Application Bundle Identifiers

macOS maps file associations to application Bundle Identifiers (reverse-domain strings such as com.microsoft.VSCode or org.videolan.vlc) rather than binary file paths. You can discover an application’s bundle ID using AppleScript or mdls:

# Query bundle ID using osascript
osascript -e 'id of app "Visual Studio Code"'

# Query bundle ID using mdls
mdls -name kMDItemCFBundleIdentifier -r /Applications/VLC.app

Inspecting Current Default Handlers

To inspect which application is currently registered to handle a given file extension or Uniform Type Identifier, pass the -x flag:

# Check default handler for .json files
duti -x json

# Check default handler for .py files
duti -x py

# Check default handler for .md files
duti -x md

The command outputs the registered application’s friendly name, its bundle identifier, and its designated role.

Setting Default Application Handlers for File Extensions

The primary command to set a default application is duti -s <bundle_id> <extension> <role>. The role argument defines access permissions:

  • all: Sets the application as the default for viewing, editing, and opening the file format.
  • editor: Sets the application as the default editor.
  • viewer: Sets the application as the default read-only viewer.

To configure Visual Studio Code as the universal default handler for source code and data files:

duti -s com.microsoft.VSCode .json all
duti -s com.microsoft.VSCode .md all
duti -s com.microsoft.VSCode .py all
duti -s com.microsoft.VSCode .ts all
duti -s com.microsoft.VSCode .yaml all

Setting Handlers for Uniform Type Identifiers (UTIs)

Instead of mapping dozens of individual extensions, you can associate standard macOS Uniform Type Identifiers directly:

# Associate plain text documents with VS Code
duti -s com.microsoft.VSCode public.plain-text all

# Associate source code text with VS Code
duti -s com.microsoft.VSCode public.source-code all

Configuring Default Handlers for URL Schemes

You can also use duti to assign default applications to standard web protocols and URL schemes:

# Set Google Chrome as default handler for HTTP and HTTPS
duti -s com.google.Chrome http all
duti -s com.google.Chrome https all

# Set Apple Mail as default mailto handler
duti -s com.apple.mail mailto all

Automating Fleet Configuration Using Declarative Settings Files

Rather than executing individual terminal commands, duti can parse declarative configuration files. Create a settings file named ~/.duti:

# BundleIdentifier        UTI/Extension    Role
com.microsoft.VSCode     .json            all
com.microsoft.VSCode     .yaml            all
com.microsoft.VSCode     .md              all
com.microsoft.VSCode     .xml             all
org.videolan.vlc         .mkv             all
org.videolan.vlc         .mp4             all

Apply all associations declared in the file in a single command:

duti ~/.duti

This command can be embedded into onboarding shell scripts, dotfiles repositories, and MDM provisioning workflows to standardize application associations across macOS fleets.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.