Action
Relative Dates - Taskpaper to Omnifocus
Summary
This action sends a Taskpaper-formatted tasklist to OmniFocus. It asks for a baseline date and parses the draft for date fields to insert a date relative to the base date.
Date field format
The format is:
<<+/-number_of_days>>
For example <<+3>>
means 3 days after the given base date. Negative numbers are possible, e.g. <<-5>>
.
Use in taskpaper
The fileds can be used in the @defer() or @due() parameters of a task. An example:
Gardening Project
- Sow flower seeds @defer(<<+0>>)
- Water the flowers @defer(<<+2>>)
- Pick the flowers @defer(<<+5>>)
This will set the defer dates for the first task to the base date, the second task two days and the third task 5 days after the base date. The project will be send to OmniFocus right into projects.
Steps
-
script
// Read draft let templateContent = editor.getText(); // Regular expression for the date fields const regExDate = /<<([+-]\d+)>>/g // Ask for the base date let p = Prompt.create(); p.addDatePicker("baseDate", "Base Date:", Date.now(),{"mode": "date"}); p.isCancellable = false; p.addButton("OK"); p.show(); // Parse date fields and replace with dates relative to base date let baseDate = new Date(p.fieldValues["baseDate"]); function parseRelativeDates(match, value) { relativeDate = new Date(baseDate.valueOf()) relativeDate.setDate(baseDate.getDate() + Number(value)) return relativeDate.toISOString().split('T')[0] } templateContent = templateContent.replace(regExDate, parseRelativeDates) // Send processed template to Omnifocus const baseURL = "omnifocus:///paste"; const target = "projects" let cb = CallbackURL.create(); cb.baseURL = baseURL; cb.addParameter("target", target) cb.addParameter("content", templateContent); let success = cb.open(); if (success) { console.log("Taskpaper added to OF") } else { console.log(cb.status); if (cb.status == "cancel") { context.cancel(); } else { context.fail(); } }
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.