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

时间:2012-10-22 12:29:35

标签: shell applescript

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

这就是我所拥有的:

declare -i count=5;
osascript -e 'tell app "Xcode" to display dialog "Counted $count items." buttons {"Continue"}'

我希望输出为Counted 5 items.,但它只是Counted $count items.}如何将shell脚本变量传递给applescript?

2 个答案:

答案 0 :(得分:5)

有三种解决方案:

  1. 使用“”代替''以便$ var将由shell扩展

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

  3. 使用AppleScript脚本
  4. Use formal command line arguments

答案 1 :(得分:2)

只是为了澄清一下,这就是我最终为了让它发挥作用而做的事情。

declare -i count=5;
osascript -e 'tell app "Xcode" to display dialog "Counted '$count' items." buttons {"Continue"}'
相关问题