惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LangChain Blog
量子位
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
人人都是产品经理
人人都是产品经理
腾讯CDC
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The Cloudflare Blog
D
Docker
Cyberwarzone
Cyberwarzone
U
Unit 42
NISL@THU
NISL@THU
C
Check Point Blog
B
Blog
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
P
Proofpoint News Feed
F
Fortinet All Blogs
V
V2EX
T
Threat Research - Cisco Blogs
T
Threatpost
S
SegmentFault 最新的问题
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
TaoSecurity Blog
TaoSecurity Blog
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
AWS News Blog
AWS News Blog
G
Google Developers Blog
美团技术团队

Origin

Agent 安全:环境变量泄露 人生第一次离职,感觉应该写点什么 在 Python 中复现 Race Condition 再看看 SQL 中的 null 迁移 Zeabur 集群 2025Q3 订阅 Recap 再见 xlog Python 的 pth 文件:在程序启动前自动执行命令 浏览器从 A 到 Z 2024Q3 订阅 Recap [备忘] Go init 行为 [随笔] 一开始就公布定价 [随笔] Server Action [随笔] Swift 异步:Task vs DispatchQueue [随笔] RSS 与稍后阅读 在 Shell 脚本中嵌入二进制文件 谈谈时区 利用 Fly.io 部署 Windmill 强制关闭 xLog 的 Dark Mode 解决 CentOS8 中 yum 源失效 [随笔] 避免完美主义导致的看似时间不够
使用 TypeScript 撰写 OmniFocus 脚本
Singee · 2023-12-13 · via Origin

OmniFocus 4 即将发布!在我多年管理我的待办的过程中,我尝试过 Todoist、滴答清单、Things、Sorted 等等几乎所有市面上的 TODO 软件,但最终,OmniFocus 终成我一直以来的最终选择。而谈及 OmniFocus 的强大性,不得不提的就是他强大的自动化能力 —— Omni Automation

Omni Automation 实际上是基于 JS 脚本的,而编写纯 JS 脚本的过程…… 一言难尽。虽然 Omni Automation 官方提供了 TypeScript 的定义文件,但一方面难以做好类型检查,另一方面其详尽程度仍有待提升(长久不更新、大量使用 any 等),此外,由于缺乏打包工具,代码逻辑的复用也显得颇为困难(我甚至很长一段时间都是靠着 Mac 版本 OmniFocus 的一个 bug 实现的逻辑复用)。

为了庆祝 OmniFocus 4 的面世,我决定将我个人开发并使用的方案整理开源,包括打包脚本和类型定义,还有我使用的一些工具函数及脚本,希望可以让更多人能够愉快地编写 OmniFocus Script。

使用

  1. 使用此模板创建一个仓库
  2. 克隆你创建的仓库
  3. 运行 pnpm install 安装依赖项
  4. 运行 pnpm build 构建脚本

脚本源码放在 src 目录中,编译结果(可被 OmniFocus Scripts 使用的)放在 dist 目录中。

撰写脚本

src 目录内的任何不以 _ 开头的 TypeScript 文件都将被视为 OmniFocus 脚本并编译(_ 开头的脚本文件被保留用于工具函数)。

任何脚本都必须遵循以下模式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const action = new PlugIn.Action(function (selection) {

});

action.validate = function (selection) {

};

export const meta: Meta = {
label: "...",
description: "...",
identifier: "...",
author: "...",
version: "0.1",
};

其中:

  1. actionmeta 是必需的,action.validate 是可选的
  2. meta 必须是脚本的最后一部分。它之后不可以有任何内容。

构建与使用

运行 pnpm build,构建后的脚本(以 .omnifocusjs 结尾)将被放置在 dist 目录下。

你可以直接将 dist 目录中的脚本拷贝到 OmniFocus 的脚本目录,也可以利用脚本进行同步。

如果你使用 iCloud 保存 OmniFocus 脚本,可以直接使用 pnpm sync 自动将构建好的脚本同步到 iCloud 中的 OmniFocus 脚本目录;如果你不使用 iCloud 而是使用了自定义路径,可修改 sync.sh 文件改变目标路径。

End

此方案我个人已用一年有余,但一方面开源版本可能有些错误,另一方面可能有更多的定制化需求。

欢迎进入 仓库 页面提交 Issue 和 PR!