View Single Post
Here's a modifed version that is derived from Curt Clifton's OmniFocus-Mail Links script

-- Derived from work that is Copyright © 2007, Curtis Clifton All rights reserved.
-- Modified to work specifically with Jott messages.

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

property messageSender : "Jott"

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 77.1.3.0.97731"
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 77.1.3.0.97731"
set messageStart to (offset of "Jott:" in theContent) + 7
set messageEnd to (offset of "Listen" in theContent) - 3
set taskName to rich text messageStart through messageEnd of theContent
if (includeSender) then
set taskName to taskName & "—" & messageSender
end if
set theDoc to first document
tell theDoc
set propRecord to {name:taskName}
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