Skip to content

Instantly share code, notes, and snippets.

@strlng
Created February 20, 2018 16:46
Show Gist options
  • Save strlng/52bcbb358a0af4682ab397cda8dd9208 to your computer and use it in GitHub Desktop.
Save strlng/52bcbb358a0af4682ab397cda8dd9208 to your computer and use it in GitHub Desktop.
Can't remember where I got this updated script, but I didn't come up with it myself.
on alfred_script(q)
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
end alfred_script
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment