View Single Post
I felt like fooling around with Applescript a bit, so I coded up a rough script to do as I suggested. Known limitations:

1) because of a bug in OmniFocus, I don't include the time in a start or due date -- OmniFocus sees the ":" in the time and gets confused. Bug report filed.
2) I don't make any attempt to preserve any hierarchical structure.
3) If you run it against actions in the Inbox, any assigned project name will be lost

It is likely that all requests for enhancement will be met with a response of "you know where the sources are, it's a good learning and character-building exercise" :-)

Code:
property DestinationEmailAddr : "someuser+omnifocus@gmail.com" -- your address goes here
property SendEmailAutomatically : true -- set to false if you want to have opportunity to verify email before sending

global msgContent

tell application "OmniFocus"
	tell front document
		tell (first document window whose index is 1)
			set theSelectedItems to selected trees of content
			set numItems to (count items of theSelectedItems)
			if numItems is 0 then
				display dialog "No tasks selected" buttons "OK"
				return
			end if
			set mailMsg to my setupEmail(DestinationEmailAddr)
			set selectNum to numItems
			repeat while selectNum > 0
				set selectedItem to value of item selectNum of theSelectedItems
				my processActionToEmail(selectedItem, mailMsg)
				set selectNum to selectNum - 1
			end repeat
			my completeEmail(mailMsg, SendEmailAutomatically)
		end tell
	end tell
end tell


on setupEmail(destinationAddress)
	tell application "Mail"
		set newmsg to make new outgoing message with properties {visible:not SendEmailAutomatically, subject:" "}
		tell newmsg
			make new to recipient at end of to recipients with properties {address:destinationAddress}
		end tell
		set msgContent to ""
		return newmsg
	end tell
end setupEmail

on completeEmail(msg, sendOrNot)
	tell application "Mail"
		tell msg
			set content to msgContent
			if (sendOrNot) then
				send msg
			end if
		end tell
	end tell
end completeEmail

on processActionToEmail(selectedItem, msg)
	tell application "OmniFocus"
		set theName to name of selectedItem
		set theProject to containing project of selectedItem
		set theContext to context of selectedItem
		set theStartDate to start date of selectedItem
		set theDueDate to due date of selectedItem
		set theDuration to estimated minutes of selectedItem
		set theNote to note of selectedItem
		set theFlagged to flagged of selectedItem
		
		set theNameStr to theName
		if (theFlagged) then
			set theNameStr to theNameStr & "!"
		end if
		
		if (theProject is not missing value) then
			set theProjectStr to ">" & name of theProject
		else
			set theProjectStr to ""
		end if
		
		if (theContext is not missing value) then
			set theContextStr to "@" & name of theContext
		else
			set theContextStr to ""
		end if
		
		-- if only one date, it is the due date (#due)
		-- if two dates, #start#due
		-- to send start date only, send #start#
		
		-- to work around an OmniFocus bug where it fails if there is a ":" in the date/time, we just use the date
		-- when OmniFocus is fixed, simply remove "short date string of" wherever it occurs in this routine
		
		if (theStartDate is not missing value) then
			set theStartDateStr to "#" & short date string of theStartDate
		else
			set theStartDateStr to "#"
		end if
		if (theDueDate is not missing value) then
			set theDueDateStr to "#" & short date string of theDueDate
		else
			set theDueDateStr to "#"
		end if
		
		if (theDuration is not missing value) then
			set theDurationStr to "$" & theDuration & " minutes"
		else
			set theDurationStr to ""
		end if
		
		theNote
		if (theNote is not "") then
			set theNote to "//" & theNote
		else
			set theNote to ""
		end if
		
		set theActionStr to "--" & theNameStr & theProjectStr & theContextStr & theStartDateStr & theDueDateStr & theDurationStr & theNote & "
"
		
		set msgContent to msgContent & theActionStr
	end tell
end processActionToEmail