OmniFocus
Control OmniFocus via JXA (JavaScript for Automation).
Requirements
- - macOS with OmniFocus 3 or 4 installed
- OmniFocus must be running (or will auto-launch)
Quick Reference
CODEBLOCK0
Commands
List/Query
| Command | Description |
|---|
| INLINECODE0 | List inbox tasks |
| INLINECODE1 |
List all folders |
|
projects [folder] | List projects, optionally filtered by folder |
|
tasks <project> | List tasks in a project |
|
tags | List all tags |
|
today | Tasks due today or overdue |
|
flagged | Flagged incomplete tasks |
|
search <query> | Search tasks by name |
|
info <taskId> | Full task details |
Create
| Command | Description |
|---|
| INLINECODE9 | Add task to inbox or project |
| INLINECODE10 |
Create project |
|
newfolder <name> | Create top-level folder |
|
newtag <name> | Create or get tag |
Modify
| Command | Description |
|---|
| INLINECODE13 | Mark complete |
| INLINECODE14 |
Mark incomplete |
|
delete <taskId> | Permanently delete |
|
rename <taskId> <name> | Rename task |
|
note <taskId> <text> | Append to note |
|
setnote <taskId> <text> | Replace note |
|
defer <taskId> <date> | Set defer date (YYYY-MM-DD) |
|
due <taskId> <date> | Set due date |
|
flag <taskId> [true\|false] | Set flagged |
|
tag <taskId> <tag> | Add tag (creates if needed) |
|
untag <taskId> <tag> | Remove tag |
|
move <taskId> <project> | Move to project |
Repeat
CODEBLOCK1
Methods: fixed, due-after-completion, defer-after-completion
Units: days, weeks, months, INLINECODE31
Output Format
All commands return JSON. Success responses include "success": true. Errors include "error": "message".
CODEBLOCK2
Examples
CODEBLOCK3
Notes
- - Task IDs are OmniFocus internal IDs (returned in all task responses)
- Dates use ISO format: YYYY-MM-DD
- Project and folder names are case-sensitive
- Tags are created automatically if they don't exist when using
tag command - All output is JSON for easy parsing
Technical Details
This skill uses JavaScript for Automation (JXA) for most operations, with AppleScript fallbacks for tag and repeat operations (due to known JXA type conversion bugs with these specific OmniFocus APIs).
The hybrid approach provides:
- - JSON output for easy parsing
- Robust escaping for special characters in tag names
- Error handling with clear messages
First run: OmniFocus may prompt to allow automation access. Enable this in System Settings > Privacy & Security > Automation.
OmniFocus
通过JXA(JavaScript for Automation)控制OmniFocus。
系统要求
- - 已安装OmniFocus 3或4的macOS系统
- OmniFocus必须正在运行(或会自动启动)
快速参考
bash
通过封装脚本运行
./scripts/of <命令> [参数...]
或直接运行
osascript -l JavaScript ./scripts/omnifocus.js <命令> [参数...]
命令
列表/查询
列出所有文件夹 |
| projects [文件夹] | 列出项目,可按文件夹筛选 |
| tasks <项目> | 列出项目中的任务 |
| tags | 列出所有标签 |
| today | 今日到期或已逾期的任务 |
| flagged | 已标记但未完成的任务 |
| search <查询> | 按名称搜索任务 |
| info <任务ID> | 完整任务详情 |
创建
| 命令 | 描述 |
|---|
| add <名称> [项目] | 将任务添加到收件箱或项目 |
| newproject <名称> [文件夹] |
创建项目 |
| newfolder <名称> | 创建顶级文件夹 |
| newtag <名称> | 创建或获取标签 |
修改
| 命令 | 描述 |
|---|
| complete <任务ID> | 标记为完成 |
| uncomplete <任务ID> |
标记为未完成 |
| delete <任务ID> | 永久删除 |
| rename <任务ID> <名称> | 重命名任务 |
| note <任务ID> <文本> | 追加备注 |
| setnote <任务ID> <文本> | 替换备注 |
| defer <任务ID> <日期> | 设置推迟日期(YYYY-MM-DD) |
| due <任务ID> <日期> | 设置截止日期 |
| flag <任务ID> [true\|false] | 设置标记状态 |
| tag <任务ID> <标签> | 添加标签(如不存在则创建) |
| untag <任务ID> <标签> | 移除标签 |
| move <任务ID> <项目> | 移动到项目 |
重复
bash
repeat <任务ID> <方法> <间隔> <单位>
of repeat abc123 fixed 1 weeks
of repeat abc123 due-after-completion 2 days
of repeat abc123 defer-after-completion 1 months
of unrepeat abc123
方法:fixed、due-after-completion、defer-after-completion
单位:days、weeks、months、years
输出格式
所有命令均返回JSON格式。成功响应包含success: true。错误响应包含error: 消息。
json
{
success: true,
task: {
id: abc123,
name: 任务名称,
note: 备注内容,
flagged: false,
completed: false,
deferDate: 2026-01-30,
dueDate: 2026-02-01,
project: 项目名称,
tags: [标签1, 标签2],
repeat: {method: fixed, rule: RRULE:FREQ=WEEKLY;INTERVAL=1}
}
}
示例
bash
添加任务到收件箱
of add 购买日用品
添加任务到特定项目
of add 审阅文档 工作项目
设置截止日期和标记
of due abc123 2026-02-01
of flag abc123 true
添加标签
of tag abc123 紧急
of tag abc123 家庭
创建重复任务
of add 每周回顾 习惯养成
of repeat xyz789 fixed 1 weeks
搜索并完成
of search 日用品
of complete abc123
获取今日任务
of today
注意事项
- - 任务ID是OmniFocus内部ID(在所有任务响应中返回)
- 日期使用ISO格式:YYYY-MM-DD
- 项目和文件夹名称区分大小写
- 使用tag命令时,如果标签不存在会自动创建
- 所有输出均为JSON格式,便于解析
技术细节
本技能主要使用JavaScript for Automation (JXA)进行操作,对于标签和重复操作则使用AppleScript作为后备方案(因为JXA在处理这些特定OmniFocus API时存在已知的类型转换错误)。
这种混合方法提供了:
- - JSON输出,便于解析
- 对标签名称中的特殊字符进行稳健转义
- 带有清晰消息的错误处理
首次运行: OmniFocus可能会提示允许自动化访问。请在系统设置 > 隐私与安全性 > 自动化中启用此权限。