Set the Default App for a File Type with duti

Script-batch change file associations on macOS instead of clicking Get Info repeatedly.

macOSautomationdutidefault-appsLow risk
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 all

02What 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

RiskLow risk
Requirementsduti installed (`brew install duti`); know the target app’s bundle ID (`mdls -name kMDItemCFBundleIdentifier /Applications/App.app`).
!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 all

05Sources

Last verified: 2026-09-18 · Category: System & Settings