KEI*_*NOS 8 macos terminal path environment-variables
在 macOS 中,通过“打开”命令打开应用程序的选项之一如下所示:
$ open -a "Google Chrome"
$ open -a "GIMP"
Run Code Online (Sandbox Code Playgroud)
但我意识到即使应用程序不在/Applications
Nor~/Applications
目录中,上面的命令也可以工作。
那么,“如何使用命令行获取此应用程序的路径”?
我尝试使用find
命令并搜索整个机器,但我认为会有更简单的方法来找到它。
原因是我需要访问“.app”目录中的 bin 文件,如下所示:
$ /path/to/GIMP.app/Contents/MacOS/GIMP-bin --help-all
Run Code Online (Sandbox Code Playgroud)
因为下面的命令似乎没有解析参数。
$ open -a "GIMP" --args --help-all
Run Code Online (Sandbox Code Playgroud)
我想我找到了另一个答案。
此脚本在检查Applescript等路径时不会启动应用程序。
由于它只是grep
的lsregister
转储结果,因此它可能不如 Applescript 准确,但到目前为止它似乎有效。
脚本:
bash
使用命令(不使用 AppleScript)查找应用程序路径的另一种方法lsregister
。
#!/bin/bash
# findApp.sh
# ==========
NAME_APP=$1
PATH_LAUNCHSERVICES="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
${PATH_LAUNCHSERVICES} -dump | grep -o "/.*${NAME_APP}.app" | grep -v -E "Caches|TimeMachine|Temporary|/Volumes/${NAME_APP}" | uniq
Run Code Online (Sandbox Code Playgroud)
用法:
$ ./findApp.sh "Google Chrome"
/Applications/Google Chrome.app
$ ./findApp.sh GIMP
/Volumes/External_HDD/Applications/GIMP/GIMP_v2.8/GIMP.app
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21474 次 |
最近记录: |