View Single Post
Modified to allow note import:

Code:
-- -------------------------------
-- This gets run from the tool bar
-- -------------------------------
on run
	tell application "OmniFocus"
		tell document window 1 of front document
			set listTrees to selected trees of content
			if (count of listTrees) = 0 then
				try
					display dialog "No tasks selected." & return
				end try
			else
				my ExportTrees(listTrees)
			end if
		end tell
	end tell
	
	-- show the results in THL
	activate application "The Hit List"
end run


-- ------------------------------------------------------------
-- Traverses the OmniFocus tree and create a task for each node
-- ------------------------------------------------------------
on ExportTrees(listTrees)
	
	using terms from application "OmniFocus"
		repeat with oTree in listTrees
			
			-- intialize task string
			set notes to ""
			set tags to ""
			set strName to ""
			set isDone to false
			
			-- get actual tree?
			set oValue to value of oTree
			
			-- Inbox does not have a name?
			try
				set strName to name of oValue
			on error
				set strName to "Inbox"
			end try
			
			-- get note if not Inbox
			-- if strName ≠ "Inbox" then
			set strNote to note of oValue
			-- end if
			
			-- get object class
			set clValue to class of oValue
			
			-- Get the context
			set oContext to context of oValue
			if oContext is not equal to missing value then
				set tags to " @" & name of oContext & " "
			end if
			
			set dteStart to start date of oValue
			set dteDue to due date of oValue
			set estimate to estimated minutes of oValue
			
			if flagged of oValue then
				set tags to tags & " @flag" & " "
			end if
			
			if completed of oValue then
				set isDone to true
			end if
			
			-- get any trees of the current tree if possible (sub trees)
			set lstSubTrees to trees of oTree
			
			-- if tree has sub trees
			if (count of lstSubTrees) > 0 then
				-- create task and move down tree
				my createTHLTask(strName & tags, strNote, dteStart, dteDue, estimate, isDone)
				ExportTrees(lstSubTrees)
			else
				-- else, just create task
				my createTHLTask(strName & tags, strNote, dteStart, dteDue, estimate, isDone)
			end if
		end repeat
	end using terms from
end ExportTrees


-- -------------------------------------
-- Create a task in the current THL list
-- -------------------------------------
on createTHLTask(theTitle, theNotes, theStartDate, theDuedate, theEstimate, theIsDone)
	-- create the record to use to create a task
	using terms from application "The Hit List"
		set params to {title:theTitle}
		if theDuedate is not missing value then
			set params to params & {due date:theDuedate}
		end if
		if theStartDate is not missing value then
			set params to params & {start date:theStartDate}
		end if
		if theNotes is not missing value then
			set params to params & {notes:theNotes}
		end if
		if theEstimate is not missing value then
			set params to params & {estimated time:theEstimate * 60}
		end if
	end using terms from
	
	-- create the task in the current THL list
	tell application "The Hit List"
		set activeGroup to get selected group
		tell activeGroup to make new task with properties params
	end tell
end createTHLTask
What was changed: Notes variable was named incorrectly; removed limitation of inbox items not passing on notes.