Mac Use
Control any macOS GUI application through a screenshot → pick element → click → verify loop.
Setup
Platform: macOS only (requires Apple Vision framework for OCR)
System binaries (pre-installed on macOS):
- -
python3 — via Homebrew (brew install python) - INLINECODE2 — built-in macOS utility
Python packages — install from the skill directory:
CODEBLOCK0
How It Works
The screenshot command captures a window, uses Apple Vision OCR to detect all text elements, draws numbered annotations on the image, and returns both:
- 1. Annotated image at
/tmp/mac_use.png — numbered green boxes around each detected text - Element list in JSON —
[{num: 1, text: "Submit", at: [500, 200]}, {num: 2, text: "Cancel", at: [600, 200]}, ...] where at is the center point [x, y] on the 1000x1000 canvas (origin at top-left)
You receive both by calling Bash (gets JSON with element list) and then Read on /tmp/mac_use.png (gets the visual). Always do both so you can cross-reference the numbers with what you see.
Quick Reference
CODEBLOCK1
Workflow
- 1. Open the target app with
open -a "App Name" (optionally with a URL or file path) - Wait for it to load: INLINECODE10
- Screenshot the app:
python3 {baseDir}/scripts/mac_use.py screenshot <app> [--id N]
This returns JSON with
file (image path) and
elements (numbered text list).
- 4. Read the annotated image at
/tmp/mac_use.png to see the numbered elements visually - Decide which element to interact with:
-
Prefer clicknum N — pick the number of a detected text element
-
Fallback click --app <app> x y — only for unlabeled icons (arrows, close buttons, cart icons) that have no text and therefore no number
- 6. Act using
clicknum, type, key, or INLINECODE19 - Screenshot again to verify the result
- Repeat from step 3
Commands
list
Show all visible app windows.
CODEBLOCK3
Returns JSON array: INLINECODE20
screenshot
Capture a window, detect text elements via OCR, annotate with numbered markers, and return the element list. The target window is automatically raised to the top before capture, so overlapping windows are handled.
CODEBLOCK4
- -
<app>: fuzzy, case-insensitive match (e.g. "chrome" matches "Google Chrome") - INLINECODE22 : target a specific window ID (required when multiple windows of the same app exist)
- Returns JSON with:
-
file: path to annotated screenshot (
/tmp/mac_use.png)
-
id,
app,
title,
scale: window metadata
-
elements: array of
{num, text, at} — the numbered clickable text elements, where
at is
[x, y] center coordinates on the 1000x1000 canvas (origin at top-left)
- - If multiple windows match, returns a list of windows instead — pick one and retry with INLINECODE33
- The image is 1000x1000 pixels with green bounding boxes and blue number badges
- Element map is saved to
/tmp/mac_use_elements.json for INLINECODE35
clicknum
Click on a numbered element from the last screenshot. This is the primary click method.
CODEBLOCK5
- -
N: the element number from the last screenshot output - Reads the saved element map, activates the window, and clicks at the element's center
- Returns JSON with
clicked_num, text, canvas coords, and absolute screen coords
click
Click at a position using canvas coordinates. Fallback only — use for unlabeled icons.
CODEBLOCK6
- - Coordinates are canvas positions (0-1000) from the screenshot image
- x=0 is left, x=1000 is right; y=0 is top, y=1000 is bottom
- Use this only when Vision OCR didn't detect the element (icon-only buttons, images, etc.)
scroll
Scroll inside an app window.
CODEBLOCK7
- - Directions:
up, down, left, INLINECODE43 - Amount: number of scroll clicks (3-5 for moderate, 10+ for fast scrolling)
- Mouse is moved to the center of the window before scrolling
type
Type text into the currently focused input field.
CODEBLOCK8
- -
--app: activates the app first to ensure keystrokes go to the right window - Uses clipboard paste (Cmd+V) for reliable Unicode/CJK support
- Always click on the target input field first before typing
key
Press a single key or key combination.
CODEBLOCK9
- -
--app: activates the app first - Common keys:
return, tab, escape, space, delete, backspace, up, down, left, INLINECODE55 - Modifiers:
cmd, ctrl, alt/opt, INLINECODE60
Important Rules
- - Always screenshot before your first interaction with an app
- Always screenshot after an action to verify the result
- Always Read the screenshot image after running the screenshot command — you need both the element list AND the visual
- Prefer
clicknum over click — only use direct coordinates for unlabeled icons - Click before typing — ensure the correct input field has focus first
- Multiple windows: if you get
multiple_windows error, use list to see all windows, then pass INLINECODE65 - Popup windows (like WeChat mini-program panels) are separate windows with their own IDs — use
list to find them and --id to target them - Wait after opening apps: use
sleep 2-3 after open -a before taking a screenshot - Activate the app before screenshot/click: prepend
osascript -e 'tell application "AppName" to activate' && sleep 1 when the target app may be behind other windows - Do not type passwords or secrets via this tool
Coordinate System (for fallback click only)
Screenshots are rendered onto a 1000x1000 canvas:
- - Origin (0, 0) is at the top-left corner
- x increases left to right (0 = left edge, 1000 = right edge)
- y increases top to bottom (0 = top edge, 1000 = bottom edge)
- The app window is scaled to fit (aspect ratio preserved), centered, with dark gray padding
Example: Order food on Meituan in WeChat
CODEBLOCK10
Mac 使用
通过 截图 → 选取元素 → 点击 → 验证 循环控制任意 macOS GUI 应用程序。
设置
平台:仅限 macOS(需要 Apple Vision 框架进行 OCR)
系统二进制文件(macOS 预装):
- - python3 — 通过 Homebrew 安装(brew install python)
- screencapture — macOS 内置工具
Python 包 — 从技能目录安装:
bash
pip3 install --break-system-packages -r {baseDir}/requirements.txt
工作原理
screenshot 命令捕获窗口,使用 Apple Vision OCR 检测所有文本元素,在图像上绘制编号标注,并返回以下两项内容:
- 1. 标注图像 位于 /tmp/mac_use.png — 每个检测到的文本周围带有编号的绿色框
- 元素列表 以 JSON 格式返回 — [{num: 1, text: 提交, at: [500, 200]}, {num: 2, text: 取消, at: [600, 200]}, ...],其中 at 是 1000x1000 画布上的中心点 [x, y](原点在左上角)
您通过调用 Bash(获取包含元素列表的 JSON)然后读取 /tmp/mac_use.png(获取视觉图像)来接收这两项内容。始终同时执行这两步,以便将编号与您看到的内容进行交叉对照。
快速参考
bash
列出所有可见窗口
python3 {baseDir}/scripts/mac_use.py list
截图 + 标注(返回图像 + 编号元素列表)
python3 {baseDir}/scripts/mac_use.py screenshot <应用> [--id N]
按编号点击元素(主要点击方法)
python3 {baseDir}/scripts/mac_use.py clicknum
在画布坐标处点击(无标签图标的备用方法)
python3 {baseDir}/scripts/mac_use.py click --app <应用> [--id N]
在窗口内滚动
python3 {baseDir}/scripts/mac_use.py scroll --app <应用> [--id N] <方向> <数量>
输入文本(使用剪贴板粘贴 — 支持所有语言)
python3 {baseDir}/scripts/mac_use.py type [--app <应用>] 此处输入文本
按下按键或组合键
python3 {baseDir}/scripts/mac_use.py key [--app <应用>] <组合键>
工作流程
- 1. 打开 目标应用,使用 open -a 应用名称(可选附带 URL 或文件路径)
- 等待 应用加载:sleep 2
- 截图 应用:
bash
python3 {baseDir}/scripts/mac_use.py screenshot <应用> [--id N]
返回包含 file(图像路径)和 elements(编号文本列表)的 JSON。
- 4. 读取 /tmp/mac_use.png 处的标注图像,以视觉方式查看编号元素
- 决定 要与哪个元素交互:
- 优先使用 clicknum N — 选择检测到的文本元素的编号
- 备用方案 click --app <应用> x y — 仅用于没有文本因此没有编号的无标签图标(箭头、关闭按钮、购物车图标)
- 6. 执行操作 使用 clicknum、type、key 或 scroll
- 再次截图 以验证结果
- 从步骤 3 重复
命令
list
显示所有可见的应用窗口。
bash
python3 {baseDir}/scripts/mac_use.py list
返回 JSON 数组:[{app:Google Chrome,title:Wikipedia,id:4527,x:120,y:80,w:1200,h:800}, ...]
screenshot
捕获窗口,通过 OCR 检测文本元素,使用编号标记进行标注,并返回元素列表。目标窗口在捕获前会自动提升到最前面,因此重叠窗口也能处理。
bash
python3 {baseDir}/scripts/mac_use.py screenshot chrome
python3 {baseDir}/scripts/mac_use.py screenshot chrome --id 4527
- - <应用>:模糊、不区分大小写的匹配(例如 chrome 匹配 Google Chrome)
- --id N:定位特定窗口 ID(当同一应用存在多个窗口时必需)
- 返回包含以下内容的 JSON:
- file:标注截图路径(/tmp/mac_use.png)
- id、app、title、scale:窗口元数据
- elements:{num, text, at} 数组 — 编号的可点击文本元素,其中 at 是 1000x1000 画布上的 [x, y] 中心坐标(原点在左上角)
- - 如果匹配多个窗口,则返回窗口列表 — 选择一个并使用 --id 重试
- 图像为 1000x1000 像素,带有绿色边界框和蓝色编号徽章
- 元素映射保存到 /tmp/macuseelements.json,供 clicknum 使用
clicknum
点击上次截图中的编号元素。这是主要的点击方法。
bash
python3 {baseDir}/scripts/mac_use.py clicknum 5
python3 {baseDir}/scripts/mac_use.py clicknum 12
- - N:上次 screenshot 输出中的元素编号
- 读取保存的元素映射,激活窗口,并在元素中心点击
- 返回包含 clicked_num、text、画布坐标和绝对屏幕坐标的 JSON
click
使用画布坐标在位置处点击。仅作为备用方法 — 用于无标签图标。
bash
python3 {baseDir}/scripts/mac_use.py click --app chrome 500 300
python3 {baseDir}/scripts/mac_use.py click --app chrome --id 4527 500 300
- - 坐标是截图图像上的画布位置(0-1000)
- x=0 为左侧,x=1000 为右侧;y=0 为顶部,y=1000 为底部
- 仅在 Vision OCR 未检测到元素时使用(仅图标按钮、图像等)
scroll
在应用窗口内滚动。
bash
python3 {baseDir}/scripts/mac_use.py scroll --app chrome down 5
python3 {baseDir}/scripts/mac_use.py scroll --app notes up 10
- - 方向:up、down、left、right
- 数量:滚动点击次数(3-5 为中等,10+ 为快速滚动)
- 滚动前鼠标会移动到窗口中心
type
在当前聚焦的输入字段中输入文本。
bash
python3 {baseDir}/scripts/mac_use.py type --app chrome hello world
python3 {baseDir}/scripts/mac_use.py type --app chrome 你好世界
- - --app:首先激活应用,确保按键输入到正确的窗口
- 使用剪贴板粘贴(Cmd+V)以获得可靠的 Unicode/CJK 支持
- 在输入文本前,始终先点击目标输入字段
key
按下单个按键或按键组合。
bash
python3 {baseDir}/scripts/mac_use.py key --app chrome return
python3 {baseDir}/scripts/mac_use.py key --app chrome cmd+a
python3 {baseDir}/scripts/mac_use.py key --app chrome cmd+shift+s
- - --app:首先激活应用
- 常用按键:return、tab、escape、space、delete、backspace、up、down、left、right
- 修饰键:cmd、ctrl、alt/opt、shift
重要规则
- - 在与应用进行首次交互之前始终先截图
- 在操作之后始终截图 以验证结果
- 运行截图命令后始终读取截图图像 — 您需要元素列表和视觉图像两者
- 优先使用 clicknum 而非 click — 仅对无标签图标使用直接坐标
- 在输入文本前先点击 — 确保正确的输入字段先获得焦点
- 多个窗口:如果遇到 multiple_windows 错误,使用 list 查看所有窗口,然后传递 --id
- 弹出窗口(如微信小程序面板)是具有自己 ID 的独立窗口 — 使用 list 找到它们并使用 --id 定位
- 打开应用后等待:在 open -a 后使用 sleep 2-3