You need to enable JavaScript to run this app. 如何使用AppleScript实现屏幕点击操作?
优惠活动
大模型
产品
解决方案
定价
更多

如何使用AppleScript实现屏幕点击操作?

AppleScript 屏幕点击实现与click at报错-25200排查

错误根因

错误码-25200为errAEEventNotPermitted,本质是macOS辅助功能权限未授予脚本运行载体。自macOS 10.14起,所有模拟输入(鼠标/键盘)的操作,必须给运行脚本的程序(如「脚本编辑器」「终端」)在「系统设置>隐私与安全性>辅助功能」中开启权限,否则System Events会直接拒绝执行点击类Apple事件。

脚本冗余问题

原脚本末尾的end run无对应run语句块,属于无效冗余代码,可能在部分环境下触发语法解析异常,需删除。

修正后可运行代码

property mousex : 1
property mousey : 1
property screenx : 2559
property screeny : 1599

tell application "System Events"
    repeat 100 times
        set clickCoordinate to {mousex mod screenx, mousey mod screeny}
        click at clickCoordinate
        set mousex to mousex + 100
        set mousey to mousey + 100
        delay 0.2
    end repeat
end tell

关键补充说明

  • 权限授予对象:必须选择实际承载脚本运行的程序(而非System Events本身),例如用脚本编辑器调试则勾选「Script Editor」,用终端执行则勾选「Terminal」
  • 坐标匹配:脚本中screenx/screeny需与当前显示器的逻辑分辨率(非Retina物理像素)一致,否则可能出现点击坐标偏移
  • 权限触发:首次运行修正后的脚本时,若未授权会弹出系统权限请求弹窗,按提示跳转设置即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.25 03:06:04