用 open -a 指定应用打开文件
open -a 可以在一次启动中覆盖默认应用关联,把文件交给任意已安装的应用,而不改变该文件的默认打开方式。
运行 `open -a "Visual Studio Code" main.py`,无论 .py 文件关联的是什么,都会用 VS Code 打开它。
01命令
命令
$ open -a "Visual Studio Code" main.py
open -a TextEdit readme.md02作用说明
-a 参数接受应用的显示名称(配合 -b 则使用 bundle identifier),macOS 会据此在已安装的应用中解析。该标志也可以单独使用:`open -a "Google Chrome"` 仅启动应用;传入多个文件则会在目标应用中全部打开。
03风险
!注意: 应用名称必须与已安装应用的显示名称一致(或用 -b 指定 bundle ID),否则 open 会报"Unable to find application"。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- open — open files and directories (macOS)依据: Documents the -a flag to specify the application used to open the given files.
最后验证: 2026-09-17 · 分类: 文件与文件夹