You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为什么AppleScript无法进入Repeat循环?开机关闭Avast窗口遇阻

修复开机自动关闭Avast窗口的AppleScript循环问题

你的脚本循环未触发的核心原因是错误使用了wait(1)语法——AppleScript中没有这个命令,正确的延迟写法是delay 1。这个语法错误会导致脚本执行到该行时直接报错终止,循环内的代码自然无法运行。

另外原脚本存在冗余代码,可做简化优化,修复后的完整代码如下:

tell application "System Events"
    repeat until bundle identifier of every application process contains "com.avast.AAFM"
        delay 1
        beep
    end repeat
    tell process "Avast"
        if front window exists then
            click attribute "AXCloseButton" of front window
        end if
    end tell
end tell

关键修改说明:

  • 替换wait(1)为delay 1:这是AppleScript标准的延迟命令,确保脚本暂停1秒后重试检查。
  • 简化循环条件:直接在repeat until中验证进程bundle ID,避免重复定义变量,让代码更简洁。
  • 优化窗口关闭逻辑:调整代码层级结构,提升可读性,同时保留原有的窗口关闭逻辑。

额外提示:

如果开机运行脚本仍有问题,可检查以下两点:

  • 确保脚本运行程序(如Script Editor、Automator)已被授予辅助功能权限(路径:系统设置→隐私与安全性→辅助功能)。
  • 验证Avast的bundle ID确实是com.avast.AAFM——可通过Activity Monitor查看进程的“标识符”确认。

内容的提问来源于stack exchange,提问作者atw58

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 10:10:26