是什么导致Apple脚本的自定义ZSH函数中引起此错误
我正在尝试制作一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在苦苦挣扎的同时,我偶然发现了 this ,我认识到我的错误是认为字符串会被评估为外壳代码通过之前。
但是我可以解决我的问题(归功于我链接到的SO答案):
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):