View Single Post
Here's a first sketch of a version which tries to export the full project/context paths:

Code:
-- Illustrative draft Ver 1.1

-- 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 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 my ReadNodePath(oParent)
				else
					set strParent to ""
				end if
				if (its class) is not folder 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, false, my ListSubNodes(its projects, blnContext, blnAll), note, strParent, missing value, missing value, missing value, missing value, false}
				end if
			end tell
		end repeat
		
		return {lstNodes, blnContext}
	end tell
end SelectedInOF

on ListSubNodes(lstNodes, blnContext, blnAll)
	if lstNodes ≠ {} then
		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 ReadNodePath(oParent)
					else
						set strParent to ""
					end if
					
					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}
				end tell
			end repeat
			return lstNodes
		end using terms from
	else
		{}
	end if
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


on ReadNodePath(oNode)
	set lst to GetNodePath(oNode, "")
	set {dlm, my text item delimiters} to {my text item delimiters, ":"}
	set str to lst as string
	set my text item delimiters to dlm
	return str
end ReadNodePath

on GetNodePath(oNode, strProjMarker)
	tell application id "OFOC"
		set {cClass, oParent, strName} to {class, container, name} of oNode
		set cParentClass to class of oParent
		if cParentClass is document or cParentClass is folder then
			if cClass is task or cClass is project then
				tell oNode
					if (cClass is project) or (it is root task of its containing project) then
						if strProjMarker ≠ "" then
							set strName to strName & strProjMarker
						end if
						
						set oFolder to folder of containing project of oNode
						if oFolder is not missing value then
							set cParentClass to folder
							set oParent to oFolder
						end if
					end if
				end tell
			end if
		end if
		if cParentClass is not document then
			return my GetNodePath(oParent, strProjMarker) & {strName}
		else
			return {strName}
		end if
	end tell
end GetNodePath