In case anyone needs to write a custom data exporter for OmniFocus, the sample code below might conceivably be helpful.
I have drafted the first version of a re-usable function, SelectedInOF(), which simply returns a nested applescript list representation of the OF tree(s) selected in a Project view or a Context view.
It is generally fairly straightforward to use its output to transfer data to some other application or format.
In another post, I have shown how SelectedInOF() can be used to export data to OmniPlan.
(A second post illustrates the use of SelectedInOF() to export from OF to the Merlin 2 project management package).
The following illustrative draft exports to OmniOutliner Pro, including the various OF fields as OmniOutliner columns. (It differs from an applescript which I posted some years ago in that it allows for export from Context views).
(Note that all the visible children of any selected parent element are exported, so there is no need to select children as well as parents)
I have drafted the first version of a re-usable function, SelectedInOF(), which simply returns a nested applescript list representation of the OF tree(s) selected in a Project view or a Context view.
It is generally fairly straightforward to use its output to transfer data to some other application or format.
In another post, I have shown how SelectedInOF() can be used to export data to OmniPlan.
(A second post illustrates the use of SelectedInOF() to export from OF to the Merlin 2 project management package).
The following illustrative draft exports to OmniOutliner Pro, including the various OF fields as OmniOutliner columns. (It differs from an applescript which I posted some years ago in that it allows for export from Context views).
(Note that all the visible children of any selected parent element are exported, so there is no need to select children as well as parents)
Code:
-- Illustrative draft Ver 0.8 -- Copies anything selected in Omnifocus (Project or Context View) into OmniOutliner -- Including the following fields: DONE, NOTE, CONTEXT or PROJECT, START, DUE, COMPLETED, DURATION, FLAGGED} -- Note that the whole sub-tree is copied, so only 'parent' elements need to be selected. -- The destination is the currently open OmniOutliner document. -- (A fresh OmniOutliner document is created if none is open) property pPROJECT : "project" property pTASK : "task" property pINBX_TASK : "inbox task" property pITEM : "item" property pColProjContext : 3 as integer property pSTART : 4 as integer property pDUE : 5 as integer property pCOMPLETED : 6 as integer property pDURATION : 7 as integer property pFLAGGED : 8 as integer on run PlaceInOO(SelectedInOF()) end run -- READ SELECTED OmniFocus CONTENT TREE(S) TO NESTED APPLESCRIPT LISTS - Ver.04 on SelectedInOF() tell application "OmniFocus" tell front window set blnContext to ((selected view mode identifier) is not equal to pPROJECT) repeat with oPanel in {content, sidebar} set lstNodes to value of (selected trees of oPanel where class of its value ≠ item) set lngNodes to count of lstNodes if lngNodes > 0 then exit repeat end repeat set blnAll to (lngNodes < 1) if blnAll then set lstNodes to value of (trees of content where class of its value ≠ item) end tell repeat with i from 1 to length of lstNodes tell item i of lstNodes if (its class) is not folder then if (number of tasks) > 0 then set item i of lstNodes to {name, completed, my ListSubNodes(its tasks, blnContext, blnAll), note, "", start date, due date, completion date, estimated minutes, flagged} else set item i of lstNodes to {name, completed, {}, note, "", start date, due date, completion date, estimated minutes, flagged} end if else if (number of projects) > 0 then set item i of lstNodes to {name, false, my ListSubNodes(its projects, blnContext, blnAll), note, "", missing value, missing value, missing value, missing value, false} else set item i of lstNodes to {name, false, {}, note, "", missing value, missing value, missing value, missing value, false} end if end if end tell end repeat return {lstNodes, blnContext} end tell end SelectedInOF on ListSubNodes(lstNodes, blnContext, blnAll) using terms from application "OmniFocus" repeat with i from 1 to length of lstNodes tell item i of lstNodes if blnContext then set oParent to its containing project else set oParent to its context end if if oParent is not missing value then set strParent to name of oParent else set strParent to "" end if if (number of tasks) > 0 then set item i of lstNodes to {name, completed, my ListSubNodes(its tasks, blnContext, blnAll), note, strParent, start date, due date, completion date, estimated minutes, flagged} else set item i of lstNodes to {name, completed, {}, note, strParent, start date, due date, completion date, estimated minutes, flagged} end if end tell end repeat return lstNodes end using terms from end ListSubNodes -- PLACING IN OMNIOUTLINER on PlaceInOO({lstTasks, blnContext}) if (length of lstTasks > 0) then tell application id "OOut" activate set docTarget to make new document at before documents set bounds of (front window) to {0, 0, 1000, 500} -- Create required columns tell docTarget if blnContext then make new column with properties {type:rich text, name:"Project"} else make new column with properties {type:rich text, name:"Context"} end if repeat with recProps in {{type:date, name:"Start"}, {type:date, name:"Due"}, {type:date, name:"Completed"}, ¬ {type:duration, name:"Duration"}, {type:checkbox, name:"Flagged", width:64}} make new column with properties recProps end repeat end tell my Tasks2OO(lstTasks, docTarget) tell docTarget to set expanded of every row to true return docTarget end tell end if end PlaceInOO on Tasks2OO(lstTasks, oParent) tell application id "OOut" tell oParent repeat with oTask in lstTasks set {strName, blnDone, lstChiln, strNote, strProjContext, dteStart, dteDue, dteDone, lngMins, blnFlagged} to oTask if length of strNote > 0 then set recRow to {topic:strName, note:strNote, expanded:true} else set recRow to {topic:strName, expanded:true} end if if blnDone then set recRow to recRow & {state:checked} tell (make new row at end of children with properties recRow) if strProjContext is not missing value then set value of cell pColProjContext to strProjContext if dteStart is not missing value then set value of cell pSTART to dteStart if dteDue is not missing value then set value of cell pDUE to dteDue if blnDone then if (dteDone is not missing value) then set value of cell pCOMPLETED to dteDone if lngMins > 0 then set value of cell pDURATION to lngMins / 60 if blnFlagged then set state of cell pFLAGGED to checked if (length of lstChiln > 0) then my Tasks2OO(lstChiln, it) end tell end repeat end tell end tell end Tasks2OO
Last edited by RobTrew; 2011-06-24 at 09:12 AM.. Reason: Ver 0.8 (including ver 0.3 of SelectedInOF())