用 duti 设置文件类型的默认打开应用

批量脚本化修改 macOS 文件关联,免去反复点“显示简介”。

macOS自动化duti 默认应用默认应用低风险
运行 `duti -s com.apple.Preview .png all` 把扩展名绑定到指定应用的所有角色。

01命令

命令
$ duti -s com.apple.Preview .png all

02作用说明

macOS 没有内置命令修改默认应用,duti 补上了这个缺口:它通过写入 LaunchServices 处理程序偏好来绑定扩展名或 UTI。结尾的 `all` 表示同时设置查看、编辑等所有角色。先用 `mdls` 拿到应用的 bundle ID,就能在多台机器上脚本化执行。

03风险

风险低风险
使用条件duti installed (`brew install duti`); know the target app’s bundle ID (`mdls -name kMDItemCFBundleIdentifier /Applications/App.app`).
!注意: bundle ID 错误时会静默失败或关联到空应用,可用 `duti -x png` 验证;新设置只对之后打开的文件生效,访达可能需要片刻才会采用。

04撤销

撤销
$ duti -s com.apple.Preview .png all

05来源

最后验证: 2026-09-18 · 分类: 系统与设置