Skip to content

Instantly share code, notes, and snippets.

@dpo
Last active December 13, 2015 20:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dpo/4967573 to your computer and use it in GitHub Desktop.
Save dpo/4967573 to your computer and use it in GitHub Desktop.
An Automator workflow to add an email from Mail.app to Things' Inbox. This is a modification of http://dl.dropbox.com/u/8019/MailToThings.scpt. Create an Automator Service, start with "Get Selected Mail Messages", then "Run AppleScript" and paste the contents of this gist as script. Subsequently, you can process the list of new todo items. I lik…
on run {input, parameters}
set todoList to {}
repeat with theMessage in input
-- Grab message info.
tell application "Mail"
-- Remove apostrophes from Subject as they wreak havoc.
set AppleScript's text item delimiters to {"'"}
set quotedSubject to ""
repeat with _item in (text items of (theMessage's subject as string))
set quotedSubject to quotedSubject & (_item as string)
end repeat
set theSubject to do shell script "echo '" & quotedSubject & "' | sed -E -e 's/^R[Ee]://g; s/^From://g;'"
set theSender to extract name from theMessage's sender
set theMessageId to theMessage's message id as string
end tell
-- Build URL to message.
-- URLs have the form message:< + message id + >. "%3C" and "%3E" stand for < and >.
set messageUrl to "[url=message:%3C" & theMessageId & "%3E]" & theSubject & "[/url]"
-- Add item to Things.
tell application "Things"
set newTodoName to theSubject & " (" & theSender & ")"
-- show quick entry panel with properties {name: newTodoName, notes: messageUrl}
set newTodo to make new to do at beginning of list "Inbox"
set name of newTodo to newTodoName
set notes of newTodo to messageUrl
set tag names of newTodo to "Follow up"
-- Add newTodo to the list of todo items.
set end of todoList to newTodo
end tell
end repeat
-- Return list of todo items to process in next action.
return todoList
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment