Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save unlocked2412/ede1bce736fbb205c5b7b64ee75601d9 to your computer and use it in GitHub Desktop.
Save unlocked2412/ede1bce736fbb205c5b7b64ee75601d9 to your computer and use it in GitHub Desktop.
OmniFocus Selected Mail Messages.applescript
tell application "Mail"
set lst to (get selection)
set _msgRecent to my GetNewerMessage(lst)
repeat with _msg in _msgRecent
set _msgSubject to _msg's subject
set _msgBody to _msg's content
set _msgSender to _msg's sender
set _msgURL to "message://%3c" & _msg's message id & "%3e" -- Fixed: OmniFocus doesn't accept "<" and ">" as part of a URL
tell application "OmniFocus"
tell quick entry
set _task to make new inbox task with properties {name:_msgSubject, note:_msgBody}
tell note of _task
insert "From: " & _msgSender & " Original Message" & (ASCII character 10) & (ASCII character 10) at before paragraphs
set value of attribute "link" of style of characters -1 thru -17 of first paragraph to _msgURL
end tell
end tell
end tell
end repeat
end tell
tell application "OmniFocus"
tell quick entry to open
end tell
tell application "System Events"
tell process "OmniFocus"
key code 125
end tell
end tell
on GetNewerMessage(lst)
if lst = {} then return
if (count lst) = 1 then return (item 1 of lst)
set msg to (item 1 of lst)
repeat with i from 1 to (count lst) - 1
using terms from application "Mail"
if CompareDates(date received of msg, date received of (item (i + 1) of lst)) then
set msg to (item i of lst)
else
set msg to (item (i + 1) of lst)
end if
end using terms from
end repeat
return msg
end GetNewerMessage
on CompareDates(A, B)
if A > B then
return true
else
return false
end if
end CompareDates
@unlocked2412
Copy link
Author

It gets the newer message in a thread.
It selects the task in quick entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment