2012-10-22 97 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"}' 
相關問題