View Single Post
OK, I dug into some of the object model for Applescript (this language, from a structure and syntax perspective, sucks) and determined that the script above *almost* works. It's accessing the Message->RawContent instead of Message->Content, so it feeds you MIME instead of Rich Text. I've made a couple of changes, and this script now works for ReQall into OmniFocus. Couple of the numeric constants had to change because of the new text that ReQall sends back.

Let me know if there are any problems.

Code:
(*Modified "Jot to OmniFocus" again by petonic on 8/18/2011. *)
(* Modified "Jott to OmniFocus" modified by dbyler to work with reQall mail. *)
-- Derived from work that is Copyright © 2007, Curtis Clifton All rights reserved.
-- Modified to work specifically with Jott messages.
-- See http://forums.omnigroup.com/showthread.php?t=7651

-- If true, then the sender of the message is included in the action's description.
property includeSender : true
property messageSender : "reQall"

on run
	tell application "Mail"
		set selectedMessages to selection
		if ((count of selectedMessages) ≠ 1) then
			display alert "Please select a message to be linked to the new action" message "This script creates a new OmniFocus action that links back to a selected message." buttons {"OK"} default button "OK" giving up after 20
			return
		end if
		my process_message(item 1 of selectedMessages)
	end tell
end run

using terms from application "Mail"
	on perform mail action with messages theMessages
		try
			set theMessageCount to count of theMessages
			repeat with theMessageIndex from 1 to theMessageCount
				my process_message(item theMessageIndex of theMessages)
			end repeat
		on error m number n
			tell application "OmniFocus"
				log "Exception in Mail action: (" & n & ") " & m
			end tell
		end try
	end perform mail action with messages
end using terms from

on process_message(theMessage)
	tell application "Mail"
		set theContent to content of theMessage
		set theDate to date sent of theMessage
		set messageId to message id of theMessage
		
	end tell
	
	tell application "OmniFocus"
		set messageStart to (offset of "Added to reqall:" in theContent) + 17
		set messageEnd to (offset of "Edit this item." in theContent) - 2
		set taskName to rich text messageStart through messageEnd of theContent
		
		if (includeSender) then
			set taskName to taskName & " (via " & messageSender & ")"
		end if
		set theDoc to default document
		--Uncomment next line if you wish to set default context. Context must exist first.
		--set taskContext to context "reQall" of default document
		tell theDoc
			-- Delete the next line, uncomment the next one if you wish to set default context
			set propRecord to {name:taskName}
			--	set propRecord to {name:taskName, context:taskContext}
			set theTask to make new inbox task with properties propRecord
		end tell
		tell theTask
			set start date to theDate
			set note to return & return
			tell note
				set theURL to "message://<" & messageId & ">"
				set linkText to theURL
				insert linkText at before first character
				set value of attribute "link" of style of paragraph 1 to theURL
			end tell
		end tell
	end tell
end process_message

on write_error_log(this_error)
	set the error_log to ((path to desktop) as text) & "Script Error Log.txt"
	try
		open for access file the error_log with write permission
		write (this_error & return) to file the error_log starting at eof
		close access file the error_log
	on error
		try
			close access file the error_log
		end try
	end try
end write_error_log