Last active
April 12, 2021 13:08
-
-
Save kstrauser/3ab6bc36b0430282296c659526869d76 to your computer and use it in GitHub Desktop.
Export an OmniOutliner document as a set of OmniFocus actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set isdate to (display dialog "When are you traveling?" default answer (current date)'s date string)'s text returned | |
tell date isdate to set travelDate to date (((its month as integer) & "/" & day & "/" & year) as text) | |
set lastOf to {} | |
tell application "OmniOutliner" | |
set theDoc to front document | |
-- Find the When and Context column numbers | |
set contextColumnNum to 0 | |
set whenColumnNum to 0 | |
set columnCount to count of columns of theDoc | |
repeat with i from 1 to columnCount | |
set theColumn to column i of theDoc | |
if name of theColumn contains "Context" then | |
set contextColumnNum to i | |
end if | |
if name of theColumn contains "When" then | |
set whenColumnNum to i | |
end if | |
end repeat | |
repeat with theRow in (every row of theDoc) | |
set titleText to topic of theRow | |
set contextText to text of cell contextColumnNum of theRow | |
set whenText to text of cell whenColumnNum of theRow | |
set levelNum to level of theRow | |
if levelNum > 1 then | |
set parentRecord to item (levelNum - 1) of lastOf | |
else | |
set parentRecord to null | |
end if | |
-- If no "Context" is given, use the parent's | |
if contextText = "" and parentRecord ≠ null then | |
set contextText to contextText of parentRecord | |
end if | |
-- If no "When" is given, use the parent's | |
if whenText = "" and levelNum > 1 then | |
set whenText to whenText of parentRecord | |
end if | |
if whenText = "" then | |
set whenSeconds to 0 | |
else | |
set whenSeconds to run script whenText | |
end if | |
set dueDate to travelDate + whenSeconds | |
if whenSeconds = 0 then | |
-- Day of travel? Default to due at 8AM. | |
set dueDate to date "8:00 AM" of dueDate | |
else if whenSeconds ≤ days * -1 or whenSeconds ≥ days * 1 then | |
-- At least 1 day before or after travel date? Default to due at 5PM. | |
set dueDate to date "5:00 PM" of dueDate | |
end if | |
tell application "OmniFocus" | |
tell default document | |
set taskProperties to {name:titleText, context:flattened context contextText, due date:dueDate} | |
if levelNum = 1 then | |
set newTask to make new project with properties taskProperties | |
else | |
set parentTask to |task| of parentRecord | |
set newTask to make new task at parentTask with properties taskProperties | |
end if | |
end tell | |
end tell | |
-- Store information about the most recent task at the given indentation level | |
set lastRecord to {task:newTask, contextText:contextText, whenText:whenText} | |
if levelNum > length of lastOf then | |
set end of lastOf to lastRecord | |
else | |
set item levelNum of lastOf to lastRecord | |
end if | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this to convert a bunch of rows in an OmniOutliner document into OmniFocus actions. This way I can build a template of things I need to do every time I travel, and with a single command turn that into a fleshed-out travel project.
Start with an OmniOutliner outline with columns "Title", "Context", and "When". "Title" and "Context" map to the expected fields.
When the script runs, it prompts for a travel date. This is combined with values in the "When" column to compute each action's due date. Values may be given like:
-3 * weeks
: the action is due at 5 PM, 21 days before the travel date.-5 * hours
: the action is due at 7PM the evening before travel.2 * days
: the action is due at 5PM, two days after the travel date.<blank>
: the action is due at 8AM the day of travel.(Note: values have to be written like
number * units
because they are actually interpreted as AppleScript expressions.)Children inherit their parent's "When" value. This lets you create a "2 days before travel" action containing all the actions that need to be done by then.
Examples of my items:
That last items is important! Every time I travel and wish I'd remember to do something, this reminds me to add it to the template so that next time I'll remember.