🍎 macOS Tricks
A running collection of macOS hints: small tools and incantations that each solve one annoyance well, and are each too short to deserve their own page. Entries stand alone — read the one you need and ignore the rest.
duti — set default apps from the CLI
Section titled “duti — set default apps from the CLI”duti manages file-type → app associations. It does what Finder’s Open With → Change All… does, except scriptable, and therefore repeatable across machines.
Associations are per-user. Run it as the account whose defaults are
changing, not under sudo.
brew install duti# for another account: su - guidos -c 'brew install duti'Find the identifiers
Section titled “Find the identifiers”Setting an association takes two things: the app’s bundle ID, and the file’s Uniform Type Identifier.
osascript -e 'id of app "Zed"' # app bundle IDmdls -name kMDItemContentType -r file.json # a file's UTIduti -x json # who currently handles .jsonSet the default
Section titled “Set the default”duti -s dev.zed.Zed public.json all # by UTIduti -s dev.zed.Zed jsonl all # by extension, for odd or dynamic typesduti -s abnerworks.Typora net.daringfireball.markdown allThe trailing argument is the role — all, viewer, or editor. Use all
unless there’s a specific reason not to.
Common UTIs
Section titled “Common UTIs”| UTI | Extension |
|---|---|
public.json |
.json |
public.plain-text |
.txt |
net.daringfireball.markdown |
.md |
public.yaml |
.yaml, .yml |
public.shell-script |
.sh |
public.data |
fallback for unknown types |
Keep it in dotfiles
Section titled “Keep it in dotfiles”The calls are idempotent, so a batch is safe to rerun and belongs with your dotfiles — a new machine then gets the same associations without a Finder session.
duti -s dev.zed.Zed public.plain-text allduti -s dev.zed.Zed public.yaml allduti -s dev.zed.Zed public.shell-script allChanges hit the LaunchServices database for the current user only, and take effect immediately — no restart, no logout. The Finder equivalent, one file type at a time, is ⌘I → Open with → Change All….