gpt4 book ai didi

macos - AppleScript 返回 "No user interaction allowed"

转载 作者:行者123 更新时间:2023-12-02 01:31:26 26 4
gpt4 key购买 nike

我尝试使用以下方式从控制台调用一个简单的消息框:

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

关于macos - AppleScript 返回 "No user interaction allowed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11871022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com