macOS xargs 不会打开 mdfind 和 grep 找到的应用程序

macOS xargs will not open app found by mdfind and grep

我正在寻找一个命令,它可以找到路径并打开所有 .app,只需在终端中更改应用程序名称。

我试过了:

mdfind "calendar.app" "kind:app" | grep -v '/Users/' | xargs open 

与日历、Safari、计算器配合良好 --> 找到并打开 .app

但是当我用 space 尝试 .app 时,它不起作用:

mdfind "Google Chrome.app" "kind:app" | grep -v '/Users/' | xargs open 

文件 /Applications/Google 和 /Users/Simon/Chrome.app 不存在。

我试过 -0, \ 但不行

你能帮帮我吗?

作为mdfind returns /Applications/Google Chrome.app,一个包含space的名称,在传递给xargs之前需要用引号括起来。

mdfind "Google Chrome.app" "kind:app" | grep -v '/Users/' | awk '{print "\x27" [=10=] "\x27" }' | xargs open

像这样,awk 将在字符串前后打印单引号 (\x27),结果是:'/Applications/Google Chrome.app'。现在,xargs 将正确理解此输入。