注:本文参与 少数派 2016 年度征文活动

装了啥丨喜欢效率工具的法官 JannerChang,用 GTD 来处理案件判决一文中介绍了我的工作流整体运转情况,因为各环节的实现细节稍微繁琐,没有详细介绍,今后我会有针对性的介绍其中的实现方法,本文并非是教程,只是分享下自己的思路和经验,希望能对读者有些许的帮助

OmniFocus 个人建议一定要购买 Mac 上的 pro 版,pro 版主要是提供了对 AppleScript 的支持,iOS 版看个人需要,我是很少打开看的。

OmniFocus 体系的建立

OmniFocus 是最符合 GTD 理念的一个 App,但也不是说我们一定要按照 GTD 的理念去做事情,适合你的 App 才是最好的,实在没有适合的就需要去调教它,我曾经也一度打算使用 THL(The Hit List)去替换 OmniFocus ,但是最终还是回到 了 OmniFocus 。

OmniFocus 能建立「顺序执行」的项目是我倚重它的主要原因,因为我的工作就是具有固定执行顺序的,可以通过 Context 很方便的查询进度安排工作。

项目分解

使用「GTD」管理自己的工作,就要对工作进行分解或者归集,我是根据案件审理流程对 Context 进行分解,每个阶段是一个 Context。

Context 官方翻译是「上下文」,我刚接触这个概念的时候很迷茫,其实翻译成「场景」更好,可以是人、地点、时间段等等,这就好理解了,我的 Context 就是工作阶段。

任务分解是个长期而持续的过程,经常会在使用的过程中进行调整,不要想一开始就能建立一个完美的体系。我也是经过多次分解再归集才形成如下的结构,

我把每个案件都当作一个项目来处理,对于每年收一百大几的案件来说每次都需要不停的新建项目,添加任务,设置 Context ,这是一个枯燥又繁琐的工程,OmniFocus 又不提供模板功能,一度想要放弃,直到看到「工具控的福音」(这绝对是国内绝无仅有的启蒙教程),里面介绍了一个「模板脚本」简直帮了我的大忙,立刻将所有案件录入 OmniFocus ,这才正式进入 OmniFocus 的世界。

我使用中的脚本

自从熟悉了 OmniFocus 的脚本后就一发不可收拾,开始寻求各种脚本和改编脚本的过程。

Templates

这是一个很复杂和强大的脚本,可以设置很多变量,相当的灵活。被我搬到了 KM 后,可以实现批量的变量赋值,原始『模板脚本』下载地址:https://github.com/lemonmade/templates,模板使用办法及说明都讲述的很清楚,实在不懂的可以与我交流。
新版本:https://github.com/FradSer/templates-for-omnifocus–2

直接使用该脚本的话需要一步一步逐一添加变量,有时候时间长了容易失败,而且一旦输入错误就没法返回修改,我就改编成 Keyboard Maestro 可操作的版本,主要是实现对变量的批量录入。

Folder

项目建立好后,因为需要对文档进行管理,使用 Folder 脚本在 Finder 中建立与项目同名的文件夹。该脚本同样是 Templates 脚本作者所写,原脚本提供了更多的功能。下载地址:https://github.com/lemonmade/support

我是根据自己的需求对脚本做了个简化,只有建立文件夹和打开文件夹的功能

Calendar

有些任务会有固定的时间去完成,OmniFocus 的提醒较弱,所以结合日历来实现会更直观。

选择你要发布到日历里的任务,设置好推迟时间,运行该脚本,选择日历即可,可批量处理。
该脚本我后续是整合到了 Done&StartNext&publish 里,同时执行多个操作。

FollowUp

有时候在你的工作流程中会有中断事项出现,在中断事项完成后才能开始下一任务

因为在工作过程中经常出现一个突发事件,导致工作流的中断,比如:调解等,在查看各阶段任务时会产生干扰,根据此需求编写一脚本如下:

-- 在一个项目中插入一个跟踪任务  
-- Context 为“FollowUp”,没有可以新建  
-- 在右侧内容窗口中,选中一个 task 或者 project 后运行脚本,会在该 task 任务所在的项目里创建一个 task 并移动到首位
 
 
 
tell front document of application "OmniFocus"  
    set contextName to first context whose name is "FollowUp"  
    tell content of document window 1  
        try  
            set OmnifocusItem to value of selected trees  
            set projectName to name of containing project of item 1 of OmnifocusItem  
        on error errText number errNum  
            if (errNum is equal to -1728) then  
                -- User cancelled.  
                display dialog "请选择一个任务或者项目后再运行"  
            end if  
        end try  
    end tell  
    tell containing project of item 1 of OmnifocusItem  
        set taskName to text returned of (display dialog "输入任务名称" default answer "输入任务名称")  
        set insertTask to make new task with properties {name:taskName, context:contextName}  
        move insertTask to beginning of tasks of containing project of item 1 of OmnifocusItem  
    end tell  
end tell

Done&StartNext&publish

该脚本是个流操作,以前我是在发完传票后挨个设置开庭时间,然后使用 Calendar 脚本发布到日历,使用中觉得还是比较麻烦,就编写该脚本。
操作流程:
1.「阅卷」后,定下开庭时间;
2.将该时间设置为「发传票」任务的截止时间;
3.然后运行该脚本。
脚本工作流程
1.将「发传票」的截止时间设置为下一个任务「开庭」的开始时间;
2.设置「发传票」任务完成;
3.将「开庭」的开始时间发布到日历。

tell front document of application "OmniFocus"  
    tell content of document window 1  
        try  
            set OmnifocusItem to value of selected trees  
            repeat with thisItem in OmnifocusItem  
                set projectObject to containing project of item 1 of thisItem  
                set dueDate to due date of item 1 of thisItem  
                set completed of item 1 of thisItem to true  
                set nextTask to next task of projectObject  
                set defer date of nextTask to dueDate  
                set deferDate to defer date of nextTask  
                if estimated minutes of nextTask is not missing value then  
                    set estimatedTime to estimated minutes of nextTask  
                else  
                    set estimatedTime to 60  
                end if  
                set dueDate to due date of nextTask  
                if note of nextTask is not "" then  
                    set eventName to note of nextTask  
                else  
                    set eventName to name of nextTask  
                end if  
                set eventStartDate to deferDate  
                set eventEndDate to eventStartDate + estimatedTime  
                set eventURL to "omnifocus:///task/" & (id of nextTask) as string  
                if dueDate is missing value then  
                    set dueDate to eventStartDate + (estimatedTime / 60) * hours  
                end if  
                tell application "Calendar"  
                    activate  
                    set theCalendars to title of every calendar  
                    try  
                        set calendarName to item 1 of (choose from list theCalendars with prompt "选择日历" without multiple selections allowed)  
                        if calendarName is not false then  
                            tell calendar calendarName  
                                make new event with properties {start date:eventStartDate, end date:dueDate, summary:eventName, url:eventURL}  
                            end tell  
                        end if  
                    end try  
                end tell

            end repeat  
        on error errText number errNum  
            if (errNum is equal to -1728) then  
                -- User cancelled.  
                display dialog "请选择一个任务或者项目后在运行"  
            end if  
        end try  
    end tell  
end tell

Shell 脚本

该脚本需要通过 brew 安装 brew fswatch 和 brew tag 来配合使用。

原脚本是通过 Hazel 监视 OmniFocus 的数据库,将完成的任务发布到 Day One 中,我这样的级别自然驾驭不了 Shell 脚本,故拜托群内A哥帮忙修改了一下。

该脚本流程:
1.通过 fswatch 监视 OmniFocus 的数据库文件;
2.发现有任务完成,根据条件判断,我是判断 Context;
3.符合条件的执行相应的操作,这里用 tag 设置 Finder 文件夹 的 tag。
原始脚本:https://github.com/RobTrew/tree-tools/tree/master/OmniFocus%20scripts/Shell%20scripts%20for%20Geektool%20or%20logging

总结

很多人使用 OmniFocus 都是因为业界的广泛宣传,刚接触「GTD」的朋友在搜索教程时看见最多的肯定是 OmniFocus ,但是 OmniFocus 上手并不容易,虽然其自身提供了完整的「GTD」流程,但是让能真正为自己服务好,就需要使用系统级脚本语言 AppleScript 对其进行扩展。

OmniFocus 提供了丰富的 AppleScript 接口,你可以提取和修改你需要的绝大部分数据,这就为你提取 OmniFocus 数据给其他 App 用,或提取其他 App 数据给 OmniFocus 提供了坚实的基础。

以上大部分脚本都在 wiki 中有详细介绍。
如有其他疑问,可加入 wiki 中的 Telegram 群,也可微博与我交流。