如何通过AppleScript关闭“您的电脑因问题重启”提示弹窗?
关闭“您的电脑因问题重启”弹窗的AppleScript方案
这个弹窗属于系统级的loginwindow进程,常规窗口枚举方法无法捕获,需要直接针对该进程的UI元素操作:
方法一:按按钮名称匹配
tell application "System Events" tell process "loginwindow" -- 定位弹窗上的“好”按钮并点击 click first button whose name is "好" end tell end tell
方法二:按弹窗描述匹配
如果不确定按钮名称,可通过弹窗的提示文本定位:
tell application "System Events" tell process "loginwindow" -- 找到包含目标提示的弹窗 set targetWindow to first window whose value of attribute "AXDescription" contains "您的电脑因问题重启" -- 点击弹窗的默认确认按钮 click default button of targetWindow end tell end tell
注意事项
- 运行脚本需要辅助功能权限:在「系统设置-隐私与安全性-辅助功能」中,添加运行脚本的应用(比如Script Editor、终端或你的测试工具)。
- 虚拟机环境下,需确保辅助功能权限已正确配置,且脚本以具备足够权限的用户身份运行。
内容的提问来源于stack exchange,提问作者nagy.zsolt.hun
相关产品推荐
相关产品推荐

