运行时依赖
安装命令
点击复制技能文档
Mac 控制 自动化 Mac UI 交互使用 cliclick(鼠标/键盘)和系统工具。 工具 cliclick:/opt/homebrew/bin/cliclick - 鼠标/键盘控制 screencapture:内置截图工具 magick:ImageMagick 用于图像分析 osascript:AppleScript 用于窗口信息 坐标系统(Eason 的 Mac Mini) 当前设置:1920x1080 显示器,1:1 缩放(无需转换!) 截图坐标 = cliclick 坐标 如果截图显示元素在(800, 500),则点击(800, 500) 对于 Retina 显示器(2x) 如果截图是逻辑分辨率的 2 倍: # 转换:cliclick_coords = screenshot_coords / 2 cliclick c:$((screenshot_x / 2)),$((screenshot_y / 2)) 校准脚本 运行以验证您的缩放因子:/Users/eason/clawd/scripts/calibrate-cursor.sh cliclick 命令 # 点击坐标 /opt/homebrew/bin/cliclick c:500,300 # 移动鼠标(无点击)- 注意:可能不会更新光标 /opt/homebrew/bin/cliclick m:500,300 # 双击 /opt/homebrew/bin/cliclick dc:500,300 # 右键点击 /opt/homebrew/bin/cliclick rc:500,300 # 点击并拖动 /opt/homebrew/bin/cliclick dd:100,100 du:200,200 # 输入文本 /opt/homebrew/bin/cliclick t:"hello world" # 按键(Return、Escape、Tab 等) /opt/homebrew/bin/cliclick kp:return /opt/homebrew/bin/cliclick kp:escape # 按键带修饰符(cmd+w 关闭窗口) /opt/homebrew/bin/cliclick kd:cmd t:w ku:cmd # 获取当前鼠标位置 /opt/homebrew/bin/cliclick p # 等待后执行操作(ms) /opt/homebrew/bin/cliclick -w 100 c:500,300 截图 # 全屏(静默) /usr/sbin/screencapture -x /tmp/screenshot.png # 带光标(可能不适用于自定义光标颜色) /usr/sbin/screencapture -C -x /tmp/screenshot.png # 交互式区域选择 screencapture -i region.png # 延迟捕获 screencapture -T 3 -x delayed.png # 3 秒延迟 工作流程:截图 → 分析 → 点击 可靠点击的最佳实践:截图、分析、点击 验证通过再次截图 示例:点击按钮 # 1. 截图 /usr/sbin/screencapture -x /tmp/before.png # 2. 查看图像,找到按钮坐标(850, 450) # (使用 Read 工具在 /tmp/before.png 上) # 3. 点击 /opt/homebrew/bin/cliclick c:850,450 # 4. 验证 /usr/sbin/screencapture -x /tmp/after.png 窗口边界 # 获取 Chrome 窗口边界 osascript -e 'tell application "Google Chrome" to get bounds of front window' # 返回:0, 38, 1920, 1080(左、上、右、下) 常见模式 Chrome 扩展图标(Browser Relay) 使用 AppleScript 找到确切的按钮位置: # 找到 Clawdbot 扩展按钮位置 osascript -e 'tell application "System Events" tell process "Google Chrome" set toolbarGroup to group 2 of group 3 of toolbar 1 of group 1 of group 1 of group 1 of group 1 of group 1 of window 1 set allButtons to every pop up button of toolbarGroup repeat with btn in allButtons if description of btn contains "Clawdbot" then return position of btn & size of btn end if end repeat end tell end tell' # 输出:1755, 71, 34, 34(x, y, 宽度,高度) # 点击按钮中心 # center_x = x + 宽度/2 = 1755 + 17 = 1772 # center_y = y + 高度/2 = 71 + 17 = 88 /opt/homebrew/bin/cliclick c:1772,88 通过颜色检测点击 如果需要找到特定颜色的元素: # 找到红色(#FF0000)像素在截图中 magick /tmp/screen.png txt:- | grep "#FF0000" | head -5 # 计算颜色区域中心 magick /tmp/screen.png txt:- | grep "#FF0000" | awk -F'[,:]' 'BEGIN{sx=0;sy=0;c=0} {sx+=$1;sy+=$2;c++} END{printf "Center: (%d, %d)\n", sx/c, sy/c}' 对话框按钮点击 截图对话框 找到按钮坐标 点击(无缩放在 1920x1080 上) # 示例:点击“OK”按钮在(960, 540) /opt/homebrew/bin/cliclick c:960,540 在文本字段中输入 # 点击焦点,然后输入 /opt/homebrew/bin/cliclick c:500,300 sleep 0.2 /opt/homebrew/bin/cliclick t:"Hello world" /opt/homebrew/bin/cliclick kp:return 帮助脚本 位于 /Users/eason/clawd/scripts/: calibrate-cursor.sh - 校准坐标缩放 click-at-visual.sh - 点击截图坐标 get-cursor-pos.sh - 获取当前光标位置 attach-browser-relay.sh - 自动点击 Browser Relay 扩展 键盘导航(当点击失败时) Google OAuth 和受保护页面阻止合成鼠标点击! 使用键盘导航: # Tab 导航元素 osascript -e 'tell application "System Events" to keystroke tab' # Shift+Tab 向后导航 osascript -e 'tell application "System Events" to key code 48 using shift down' # Enter 激活焦点元素 osascript -e 'tell application "System Events" to keystroke return' # 完整工作流程:Tab 3 次然后 Enter osascript -e 'tell application "System Events" keystroke tab delay 0.15 keystroke