Browse Source

New post: TaskPaper 3: Child-aware Archiving

pull/1/head
Annika Backstrom 1 year ago
parent
commit
64b8c91338
1 changed files with 115 additions and 0 deletions
  1. 115
    0
      content/taskpaper-3-child-aware-archiving.md

+ 115
- 0
content/taskpaper-3-child-aware-archiving.md View File

@@ -0,0 +1,115 @@
1
+Title: TaskPaper 3: Child-aware Archiving
2
+Slug: taskpaper-3-child-aware-archiving
3
+Summary: Here's a TaskPaper "Archive" replacement that keeps child tasks with
4
+    their parents.
5
+Date: 2018-06-10 12:11
6
+Category: Technology
7
+Tags: taskpaper, javascript
8
+
9
+[TaskPaper 3][1] is a critical part of my workflow.[ref]For more about
10
+why I like and how I use TaskPaper, see [IFTTT and Taskpaper TODO
11
+Workflow][2].[/ref] I use it to track what's happening now and what's up
12
+next, but also what I've done recently. Having a log of recent tasks is
13
+great during times of retrospection or when timeline questions come up.
14
+
15
+In TaskPaper, completed tasks are tagged with `@done`. The built-in
16
+"Archive" action moves all done tasks to an "Archive" Project.
17
+Unfortunately, Archive will also disconnect child tasks from their
18
+parents:
19
+
20
+<video autoplay loop controls preload="none"
21
+    poster="/media/2018/06/taskpaper.jpg"
22
+    src="/media/2018/06/taskpaper.mp4"></video>
23
+
24
+*Fotunately*, TaskPaper is scriptable with JavaScript, and we can create
25
+a custom action with archiving more to my liking.
26
+
27
+## Goals
28
+
29
+Ideally, we would not move child tasks to the Archive until their parent
30
+task is complete. The default behavior disconnects children from their
31
+parents, losing important context. Here's a document before archiving:
32
+
33
+```
34
+Inbox:
35
+  - Build login page @due(2018-12-01)
36
+    - Add auth0 library to composer.json @done(2018-08-17)
37
+    - Write tests
38
+    - Create tables
39
+  - Book hotel for trip to sf @done(2018-06-10)
40
+    - Get corporate card @done(2018-06-10)
41
+```
42
+
43
+And, after archiving:
44
+
45
+```
46
+Inbox:
47
+  - Build login page @due(2018-12-01)
48
+    - Write tests
49
+    - Create tables
50
+Archive:
51
+  - Add auth0 library to composer.json @done(2018-08-17)
52
+  - Book hotel for trip to sf @done(2018-06-10)
53
+    - Get corporate card @done(2018-06-10)
54
+```
55
+
56
+Our history no longer tells us why the auth0 task existed. My preference
57
+is to keep the hierarchy, and only archive the "top-level" tasks that
58
+sit directly below a Project.
59
+
60
+## The "Smart Archive" extension
61
+
62
+Here's an extension that accomplishes our goal.
63
+
64
+1. Ensure an "Archive" project exists
65
+2. Find all `@done` tasks that are immediate children of projects (excluding the
66
+Archive project)
67
+3. Move these items to the Archive, preserving their current order in the
68
+document
69
+
70
+```js
71
+var TaskPaper = Application('TaskPaper');
72
+
73
+function fn(editor, options) {
74
+    var outline = editor.outline;
75
+    var archive = outline.evaluateItemPath("//Archive:")[0];
76
+
77
+    var insertBeforeElement = archive ? archive.firstChild : undefined;
78
+
79
+    outline.groupUndoAndChanges(() => {
80
+        if (typeof archive === "undefined") {
81
+            archive = outline.createItem("Archive:");
82
+            outline.root.appendChildren(archive);
83
+        }
84
+
85
+        var topLevelItems = outline.evaluateItemPath("project/@done except Archive//*")
86
+
87
+        topLevelItems.map(item => {
88
+            item.removeFromParent();
89
+            if (insertBeforeElement) {
90
+                archive.insertChildrenBefore(item, insertBeforeElement)
91
+            } else {
92
+                archive.appendChildren(item);
93
+            }
94
+        });
95
+    });
96
+}
97
+
98
+TaskPaper.documents[0].evaluate({
99
+    script: fn.toString()
100
+})
101
+```
102
+
103
+If we install this script to the TaskPaper Scripts folder, we can quickly run it
104
+using `cmd-shift-P` and typing the script name. I find it's also helpful to
105
+[rebind the default Archive shortcut][6] in the Keyboard preference pane to
106
+combat muscle memory.
107
+
108
+For more information about TaskPaper scripting, see the [Scripting API][3], [Extensions Wiki][4], and [script installation guide][5].
109
+
110
+  [1]: https://www.taskpaper.com/
111
+  [2]: ifttt-and-taskpaper-todo-workflow
112
+  [3]: https://guide.taskpaper.com/reference/scripting
113
+  [4]: http://support.hogbaysoftware.com/t/taskpaper-extensions-wiki/1628/1
114
+  [5]: http://support.hogbaysoftware.com/t/how-do-i-run-install-a-script/1740?u=jessegrosjean
115
+  [6]: https://support.apple.com/kb/PH25377

Loading…
Cancel
Save