Inbox Glue

February 19th, 2009  |  Published in ruby  |  1 Comment

MailTags is handy because it lets you assign due-dates (“tickle dates”) to incoming messages. One problem I’ve got with anything like that, though, is that I’ve already got an inbox for e-stuff in the form of Evernote. It’s possible to forward messages to Evernote for clipping, but I like having a list of actionable messages for a given day in one place, hence the script below.

It goes through my ‘tickler’ mail folder and pulls anything with a tickle date of the current day or earlier, finds Evernote notes tagged with today’s date (I haven’t gotten around to parsing the tags so I can grab earlier notes), and compiles them into a single Evernote note item. I write other to-dos on a printed copy, which gives me a one-stop place to find everything.

One beef: Evernote’s HTML interpreter is sub-par. It doesn’t understand Apple’s message:// URIs, so it’s not possible to dump an Evernote item with hyperlinks to messages as they appear in I’m guessing the way around that might involve importing an HTML file (instead of building a note object and storing HTML in it), but I haven’t bothered testing yet. I just dump plain text into the note for now.

One semi-neat thing is its use of the Mac ‘Summarize’ feature in Applescript. It lets you take something like this article from the AP and render it into a summary:

“President Barack Obama approved adding some 17,000 U.S. troops for the flagging war in Afghanistan, his first significant move to change the course of a conflict that his closest military advisers have warned the United States is not winning.”

The AppleScript syntax for that is just:

summarize "some text" in 1

where “1” is the number of paragraphs you want back.

In Ruby/appscript, it’s:

osax.summarize("some text")

So when the script goes through the day’s e-mail messages, it passes the message text through the summarizer, which has a better chance of getting me a useful nut than a simple string.slice[0,200] approach (though sometimes it misses in a way that at least provokes some stimulating head-scratching).

One other curiosity in this script. Sometimes native Applescript has to use the ‘using terms from’ convention. MailTags is one such case. It tells Applescript that you’re ‘tell’-ing Mail something, but you need the supplemental dictionary provided by the MailTags add-on. rb-appscript doesn’t allow for that, quite, so you’ve got to do a little dancing around.

#!/usr/bin/env ruby

require 'rubygems'

require 'appscript'

require 'Date'

include Appscript

require 'osax'

include OSAX

require '/Users/mph/lib/ruby/mailtags.rb'

require 'erb'

today ="%Y-%m-%d")

title = "Tickler File for #{"%A, %B %d")}"

mail = app("Mail", MailTags)

en = app("EverNote")

nb = en.notebooks["tickler"]

ical = app("ical")

note = ""

messages = mail.accounts["Gmail"].mailboxes["tickler"].messages.get

notes = nb.notes.get

todays_notes = []

todays_messages = []

notes.each do |n|

  n.tags.get.each do |t|

    if t.to_s =~ /##{today}/

      todays_notes << n




messages.each do |m|

  due_date = m.due_date.get.strftime("%Y-%m-%d")

  if due_date >= today

    todays_messages << m



template = <<END

Tickler File for <%="%A, %B %d") %>

Today's Messages


<% todays_messages.each do |m| %>

  [  ] <%= m.subject.get %> (due <%= m.due_date.get.strftime("%m/%d") %>)

  from <%= m.sender.get %> on <%= m.date_sent.get.strftime("%A, %B %d") %>

  "<%= osax.summarize(m.content.get).strip %>"


<% end %>

Today's Notes


<% todays_notes.each do |n| %>

[  ] <%= n.title.get %>

<%end %>


tickle_text =

tickle_note = en.create_note(:title => title, :notebook => "Inbox", :with_text => tickle_text)


  1. Panopticon 0.1 :: dot unplanned says:

    June 29th, 2010 at 2:28 pm (#)

    […] e-mail and RSS items through the summarize service (described here last February) to populate the to-do […]

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.