Set the Default App for a File Type with duti
Script-batch change file associations on macOS instead of clicking Get Info repeatedly.
Run `duti -s com.apple.Preview .png all` to bind the extension to an app for viewing, editing, and all roles.
01Command
Command
$ duti -s com.apple.Preview .png all02What it does
macOS has no built-in command for changing default applications; duti fills that gap by writing the LaunchServices handler preference for an extension or UTI. The trailing `all` sets every role (viewer, editor, shell). Getting the app’s bundle identifier with `mdls` makes it scriptable across many machines.
03Risk
!Warning: Wrong bundle IDs fail silently or associate with nothing — verify with `duti -x png`. Newly set handlers apply to files opened afterwards; Finder may need a moment to pick them up.
04Undo
Undo
$ duti -s com.apple.Preview .png all05Sources
- defaults – Read and write macOS user defaultsEvidence: duti writes the LaunchServices handler preferences that Finder honors
- duti – set default applications on macOSEvidence: duti writes default-handler preferences for file extensions and URL schemes via LaunchServices
Last verified: 2026-09-18 · Category: System & Settings