2012-08-08 39 views
6

我試着用打電話從控制檯一個簡單的消息框:的AppleScript返回「不允許用戶交互」

osascript -e "display dialog \"hello\"" 

但它返回:

execution error: No user interaction allowed. (-1713) 

有沒有解決辦法?

編輯:

解決方法是:tell application "AppleScript Runner" to display dialog "Hello"

回答

-6

看到這個answer,它包含了從控制檯工作的例子。

8

您可以告訴SystemUIServer等後臺進程顯示對話框。默認關閉對話框後,以前聚焦的窗口不會重新獲得焦點。如果系統事件和AppleScript Runner之前沒有運行,則它們可能會有小的延遲。

answer=$(osascript -e 'try 
tell application "SystemUIServer" 
set answer to text returned of (display dialog "" default answer "") 
end 
activate app (path to frontmost application as text) 
answer 
end' | tr '\r' '\n') 
[[ -z "$answer" ]] && exit 

你也可以告訴最前面的應用程序顯示一個對話框,但它往往是稍微慢一些。如果應用程序沒有響應,對話框將不會立即顯示。如果MPlayer OS X位於最前面,則文本對話框不接受任何鍵盤輸入。

answer=$(osascript -e 'try 
tell application (path to frontmost application as text) 
text returned of display dialog "" default answer "" 
end 
end' | tr '\r' '\n') 
[[ -z "$answer" ]] && exit