我尝试使用以下命令从控制台调用简单的消息框:
osascript -e "display dialog \"hello\""
但它返回:
execution error: No user interaction allowed. (-1713)
有解决方法吗?
编辑:
解决方法是:tell application "AppleScript Runner" to display dialog "Hello"
答案 0 :(得分:9)
您可以告诉像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
答案 1 :(得分:-5)
请参阅此问题以获得解决方案,它包含一个可在控制台中运行的示例:
"No user interaction allowed" When running AppleScript in python