2012-10-22 98 views
4

我有一个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的?

回答

5

有三种解决方案:

  1. 使用“”,而不是“”,以便$ VAR将由外壳

  2. 扩展关闭报价,把var和与重新打开没有空格(例如'string'$ var'rest')。但是,如果变量可以包含空格,这是不安全的。

  3. Use formal command line arguments与您的AppleScript脚本

+0

干杯。我使用第二种方法,因为我没有空格,这是最容易实现的。 –

+0

如果var包含空格,我发现这个工作:'osascript -e'显示对话框“string1”“$ var”'string2“'' – jrodatus

2

只是为了澄清,这是我最后还是没得到它的工作。

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