Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rentzsch/05d155147e894bd2730f to your computer and use it in GitHub Desktop.
Save rentzsch/05d155147e894bd2730f to your computer and use it in GitHub Desktop.
OmniFocus Selected Mail Messages.applescript
(*
OmniFocus Selected Mail Messages.applescript
Copyright (c) 2015 Jonathan 'Wolf' Rentzsch: http://rentzsch.com
Some rights reserved: http://opensource.org/licenses/mit
Pure AppleScript reimplementation of OmniGroup's Clip-o-Tron for OmniFocus.
Hopefully this implementation will be more resilient against OS X, Mail, and OmniFocus updates.
Successfully tested against OS X 10.10.1, OmniFocus 1.10.6, and OmniFocus 2.0.4.
References:
<http://daringfireball.net/2007/12/message_urls_leopard_mail>
<http://forums.omnigroup.com/showthread.php?t=30754>
<http://shawnblanc.net/box/smarter_clip-o-tron.txt>
*)
tell application "Mail"
set _sel to the selection
repeat with _msg in _sel
set _msgSubject to _msg's subject
set _msgBody to _msg's content
set _msgSender to _msg's sender
set _msgURL to "message://<" & _msg's message id & ">"
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" to keystroke tab
@Pals8080
Copy link

Pals8080 commented May 7, 2015

Can a keyboard shortcut be setup to use in Apple Mail to send email messages to OmniFocus Selected Mail Messages like OmniFocus's Clip-o-Tron?

@orionp
Copy link

orionp commented May 7, 2015

Nicely done; thank you!

@rentzsch
Copy link
Author

rentzsch commented Dec 4, 2015

@firles
Copy link

firles commented Jan 5, 2017

Version 2.8.1 (v113.2.5 r276599) or OmniFocus seems to break the script, when combined with Sierra Mail (Version 10.2 (3259)).

The error is:

Error Number: 1

OmniFocus got an error: Unable to convert the string “message://[email protected]” to a url. Make sure that the string is a valid URL, including quoting characters that aren't valid in URLs.

Anyone have any luck resolving that? Thanks!!

@strlng
Copy link

strlng commented Jan 11, 2017

firles you need to encode the "<" and ">" first now it seems. Replace line 23 with this

set _msgURL to "message://%3C" & _msg's message id & "%3e"

@MarkjanJ
Copy link

Replacement line helped. Thank you very much!!

@ffurre
Copy link

ffurre commented Feb 14, 2017

Can you please add moving the mail that has been acted on to a different folder?

@genecivillico
Copy link

Something seems to be different in OF3 that is breaking this. Specifically, the quick entry window appears with all the tasks entered; however, after hitting save the actions do not appear in the inbox, or anywhere else. I haven't investigated in detail...

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