[英]Zsh function with argument stopped working with AppleScript
I have a function in my ~/.zshrc
that runs an AppleScript like so我的~/.zshrc
.zshrc 中有一个 function 像这样运行 AppleScript
qapp() {
osascript -e 'quit app "$1"'
}
This function would kill an app in terminal by using it like so $ qapp Messages
to quit the Messages app.这个 function 会像这样使用$ qapp Messages
以退出Messages应用程序来杀死终端中的应用程序。 I am trying to figure out why this all of a sudden stopped working as in it no longer quits the application, no error message comes up or anything.我试图弄清楚为什么这突然停止工作,因为它不再退出应用程序,没有出现错误消息或任何东西。 The only thing I did after testing it was I committed the file and pushed it to my remote repo.测试后我唯一做的就是提交文件并将其推送到我的远程仓库。 When I add an echo $1
in the function, it prints the expected argument.当我在 function 中添加echo $1
时,它会打印预期的参数。 I have no clue how this happened or why the script wouldn't actually quit the app.我不知道这是怎么发生的,也不知道为什么脚本实际上不会退出应用程序。 If I run that command from the command line, it works.如果我从命令行运行该命令,它就可以工作。 I am running macOS 11.3.1 and I have tested another function that uses AppleScript to empty the trash and it works fine.我正在运行 macOS 11.3.1,并且我测试了另一个使用 AppleScript 清空垃圾箱的 function,它工作正常。
Could this be an issue with my $PATH
?这可能是我的$PATH
的问题吗? I pasted it below just in case.我把它贴在下面以防万一。
/usr/local/opt/ruby/bin:/Users/USERNAME/.gem/ruby/2.6.0/bin:/Users/USERNAME/.gem/ruby/2.6.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
The following works for me:以下对我有用:
qapp() {
osascript -e "quit app \"$1\""
}
Note: In 'quit app "$1"'
as in your OP, $1
does not get expanded as it's wrapped in single-quotes .注意:在您的 OP 中'quit app "$1"'
中, $1
不会被扩展,因为它包含在单引号中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.