我试着用打电话从控制台一个简单的消息框:的AppleScript返回“不允许用户交互”
osascript -e "display dialog \"hello\""
但它返回:
execution error: No user interaction allowed. (-1713)
有没有解决办法?
编辑:
解决方法是:tell application "AppleScript Runner" to display dialog "Hello"
我试着用打电话从控制台一个简单的消息框:的AppleScript返回“不允许用户交互”
osascript -e "display dialog \"hello\""
但它返回:
execution error: No user interaction allowed. (-1713)
有没有解决办法?
编辑:
解决方法是:tell application "AppleScript Runner" to display dialog "Hello"
看到这个answer,它包含了从控制台工作的例子。
您可以告诉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