macOS Desktop Automation (application-use)
A CLI to automate macOS applications.
install
CODEBLOCK0
🚀 Core Workflow
- 1. Open:
application-use open --appName "<Name>" -- Auto-shows initial snapshot. - Interact: Use hints (e.g.,
[A]) to click, type, or scroll. - Auto-Update: Commands (
open, click, type, sendkey, scroll) automatically display an updated snapshot.
[!TIP]
Use application-use snapshot only when you need a fresh view without any action (e.g., after waiting for dynamic content).
🛠 Command Reference
| Command | Usage | Description |
|---|
| INLINECODE9 | INLINECODE10 | Opens app and shows snapshot. |
| INLINECODE11 |
click A [--right] [--double] | Clicks element by hint letter. |
|
fill |
fill A "text" or
fill "text" | Fills text into hint or focused element. |
|
sendkey |
sendkey enter,
sendkey cmd+v | Sends single or shortcut keys. |
|
scroll |
scroll "Main" down [500] | Scrolls area by name/hint. |
|
screenshot |
screenshot [path] [--frame] | Captures window or specific coordinates. |
|
search |
search "Safari" | Finds installed application names. |
|
close |
close --appName "Safari" | Quits the specified application. |
|
type |
type "text" | Types text into the focused element. |
🏷 Hint System
- - Elements:
[A], [B], [AA]... (Interactive elements). - Areas:
[a], [b]... (Targets for scrolling). - Special Marks:
(*) = OCR-detected; (+) = Newly added since last snapshot.
⚡️ Common Automation Patterns
Form Filling & Submission & scroll
CODEBLOCK1
Browser Navigation
CODEBLOCK2
File Operations (Finder)
CODEBLOCK3
macOS 桌面自动化(application-use)
用于自动化 macOS 应用程序的命令行工具。
安装
bash
npm i -g application-use
🚀 核心工作流程
- 1. 打开:application-use open --appName <名称> — 自动显示初始快照。
- 交互:使用提示(例如 [A])进行点击、输入或滚动。
- 自动更新:命令(open、click、type、sendkey、scroll)会自动显示更新后的快照。
[!提示]
仅在需要获取无任何操作的新视图时使用 application-use snapshot(例如等待动态内容后)。
🛠 命令参考
| 命令 | 用法 | 描述 |
|---|
| open | open --appName Safari | 打开应用并显示快照。 |
| click |
click A [--right] [--double] | 通过提示字母点击元素。 |
| fill | fill A 文本 或 fill 文本 | 向提示元素或焦点元素填充文本。 |
| sendkey | sendkey enter、sendkey cmd+v | 发送单键或快捷键。 |
| scroll | scroll Main down [500] | 按名称/提示滚动区域。 |
| screenshot | screenshot [路径] [--frame] | 捕获窗口或特定坐标。 |
| search | search Safari | 查找已安装的应用程序名称。 |
| close | close --appName Safari | 退出指定应用程序。 |
| type | type 文本 | 向焦点元素输入文本。 |
🏷 提示系统
- - 元素:[A]、[B]、[AA]...(可交互元素)。
- 区域:[a]、[b]...(滚动目标)。
- 特殊标记:(*) = OCR 检测;(+) = 自上次快照后新增。
⚡️ 常见自动化模式
表单填写、提交与滚动
bash
application-use open --appName Safari
application-use fill A user@example.com # 填写邮箱
application-use sendkey tab # 下一个字段
application-use fill password # 焦点填充密码
application-use sendkey enter # 提交
application-use scroll d down 1000 # 向下滚动区域 d
浏览器导航
bash
application-use open --appName Safari
application-use fill A https://google.com && application-use sendkey enter
等待加载,然后通过自动快照的提示进行交互
文件操作(访达)
bash
application-use open --appName Finder
application-use sendkey cmd+shift+g # 前往文件夹
application-use fill /Users/name/Downloads && application-use sendkey enter
通过右键在新标签页中打开
application-use click A --right # 右键点击文件夹/文件(提示 A)
application-use click B # 从菜单中点击在新标签页中打开(提示 B)