Macos “AppleScript返回”;“不允许用户交互”;
我尝试使用以下命令从控制台调用一个简单的messagebox:Macos “AppleScript返回”;“不允许用户交互”;,macos,applescript,Macos,Applescript,我尝试使用以下命令从控制台调用一个简单的messagebox: osascript -e "display dialog \"hello\"" 但它的回报是: execution error: No user interaction allowed. (-1713) 有解决办法吗 编辑: 解决方法是:告诉应用程序“AppleScript Runner”显示对话框“Hello”有关解决方案,请参见此问题,它包含一个从控制台运行的示例: 您可以让SystemUIServer之类的后台进程显示该对
osascript -e "display dialog \"hello\""
但它的回报是:
execution error: No user interaction allowed. (-1713)
有解决办法吗
编辑:
解决方法是:
告诉应用程序“AppleScript Runner”显示对话框“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