是什么导致Apple脚本的自定义ZSH函数中引起此错误

发布于 2025-02-03 11:55:38 字数 1075 浏览 3 评论 0原文

我正在尝试制作一个ZSH函数,我可以通过终端使用终端来退出给定的应用程序,就像该应用程序使用< cmd,q&gt一样退出给定应用程序。快捷方式(因此不仅仅是pkill)。

我使用了如何从在这里,我确认我的zsh函数/参数使用语法似乎是正确的href =“ https://stackoverflow.com/questions/55127741/how-do-you-pass-arguments-to-custom-zsh-functions#:%7e:text=how%20I%20Would%20WOUDD%20WRITE; %3A“>此问题和

quitapp() {
  osascript -e 'quit app ${1:?"The application must be specified."}'
}

但是,我通过尝试退出Spotify进行了测试,但是当我尝试这样做时,

quitapp Spotify

我遇到了此错误:(

9:10: syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741)

我尝试使用小写和大写,并尝试将Spotify包裹在双引号或不带双引号的情况下,并且总是相同的错误)。

我在做什么错?

I am trying to make a zsh function that I can pass an argument to in order to quit a given app using the terminal in the same way that the app quits with the <CMD,Q> shortcut (so not just pkill).

I used the example of how to quit apps in macOS terminal from here and I confirmed that my Zsh function/argument use syntax seems correct from looking at this question and this documentation

quitapp() {
  osascript -e 'quit app ${1:?"The application must be specified."}'
}

However, I tested it by trying to quit Spotify but when I tried to do so like this:

quitapp Spotify

I got this error:

9:10: syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741)

(I tried using both lowercase and uppercase, and tried to enclose Spotify in double quotes or without double quotes, and always the same error).

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2025-02-10 11:55:38

在苦苦挣扎的同时,我偶然发现了 this ,我认识到我的错误是认为字符串会被评估为外壳代码通过之前。

但是我可以解决我的问题(归功于我链接到的SO答案):

qapp() {
    osascript -e "quit app \"$1\""
}

While struggling some more I stumbled upon this and I recognize that my mistake was thinking that string would be evaluated as shell code before being passed.

But I can just solve my question with (credit to the SO answer I linked to):

qapp() {
    osascript -e "quit app \"$1\""
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文