用 duti 设置文件类型的默认打开应用
批量脚本化修改 macOS 文件关联,免去反复点“显示简介”。
运行 `duti -s com.apple.Preview .png all` 把扩展名绑定到指定应用的所有角色。
01命令
命令
$ duti -s com.apple.Preview .png all02作用说明
macOS 没有内置命令修改默认应用,duti 补上了这个缺口:它通过写入 LaunchServices 处理程序偏好来绑定扩展名或 UTI。结尾的 `all` 表示同时设置查看、编辑等所有角色。先用 `mdls` 拿到应用的 bundle ID,就能在多台机器上脚本化执行。
03风险
!注意: bundle ID 错误时会静默失败或关联到空应用,可用 `duti -x png` 验证;新设置只对之后打开的文件生效,访达可能需要片刻才会采用。
04撤销
撤销
$ duti -s com.apple.Preview .png all05来源
- defaults – Read and write macOS user defaults依据: duti writes the LaunchServices handler preferences that Finder honors
- duti – set default applications on macOS依据: duti writes default-handler preferences for file extensions and URL schemes via LaunchServices
最后验证: 2026-09-18 · 分类: 系统与设置