我尝试使用以下命令从控制台调用一个简单的消息框:
osascript -e "display dialog \"hello\""
但它返回:
execution error: No user interaction allowed. (-1713)
有解决方法吗?
编辑:
解决方法是:tell application "AppleScript Runner" to display dialog "Hello"
我尝试使用以下命令从控制台调用一个简单的消息框:
osascript -e "display dialog \"hello\""
但它返回:
execution error: No user interaction allowed. (-1713)
有解决方法吗?
编辑:
解决方法是:tell application "AppleScript Runner" to display dialog "Hello"
您可以告诉 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
See this question for a solution, it contains an example that works from the console:
"No user interaction allowed" When running AppleScript in python