如何将变量从shell脚本传递给applescript

Dom*_*ock 4 shell applescript

我有一个shell脚本,用于检查文件夹是否有一定数量的文件,并向用户显示错误消息.我使用applescript来显示错误消息.有没有办法将shell脚本的变量传递给AppleScript?

这是我有的:

declare -i count=5;
osascript -e 'tell app "Xcode" to display dialog "Counted $count items." buttons {"Continue"}'
Run Code Online (Sandbox Code Playgroud)

我想要输出,Counted 5 items.但它只是出来的Counted $count items.如何我将shell脚本变量传递给applescript?

jra*_*jav 5

有三种解决方案:

  1. 使用""代替'',以便shell将扩展$ var

  2. 关闭引号,放入var,然后重新打开没有空格(例如'string'$ var'rest of string').但是,如果变量可以包含空格,则这是不安全的.

  3. 在AppleScript脚本中使用正式的命令行参数