I needed this in order to work around the absence of a 'task group' class.
When
importing, projects are created in expanded state, but task groups are not. They can't be, because they only become task groups after a child is created (obvious when you have experienced the mess which results when ignoring this).
The script now checks in what type of container a list of tasks will be created.
If it's a task, the script expands the new task group after the first child is created.
Now it can also paste the childrens' notes, which is the purpose of the exercise.
(I use UI scripting because my notes have a lot of formatting, which I do not want to loose).
Earlier I was trying to do this in the routine which creates the tasks, but after some reshuffling the solution became somewhat simpler.
Here is the routine that processes the task list:
Code:
-- Recursively create tasks in current project
-- Flag condition where parent is a task
-- parameters: list of tasks in Mori
-- OmniFocus item in which to create tasks from entryList
-- (a project on first entry)
-- returns: nothing
on processEntries(entryList, refOmniNode)
tell front document of application "Mori"
set currentNode to ""
tell front document of application "OmniFocus" to set boolIsTask to (class of refOmniNode is task)
set taskCount to count entryList
repeat with i from 1 to taskCount
set refMoriTask to item i of entryList
-- tell subroutine to only expand parent first time
set boolExpandParent to (i = 1 and boolIsTask)
set currentNode to my createTask(refMoriTask, refOmniNode, boolExpandParent)
if entries of refMoriTask is not {} then -- has children
set children to my listEntriesSorted(refMoriTask)
my processEntries(children, currentNode) -- go deeper
end if
end repeat
end tell
end processEntries