Niclas Nilsson home

GTD, Things.app and Apple Mail

Early this year, I examined the state of GTD apps for the Mac. I was previously using Actiontastic, but the development kind of halted. A pity, CloudKit that Jon Crosby puts his time into primarily seems very interesting. In any case, after going through all the apps I could find, I discovered that Things.app is the GTD app I really like best. It’s clean and simple, and pleasing to the eye, and I do like their tagging approach instead of strict one-to-one relationship between a task and a context (a context in GTD is more or less a ‘location’, a context in which a task can be accomplished). However, there is a problem - since Things lacks AppleScript support, it doesn’t play well with Apple Mail.

In my case, almost all my actions enter my life through the mailbox. As many OS X users, I run Apple Mail, and I really need my GTD app to to easily integrate with Mail.app. When it comes to Things, you can drag and drop a mail to the Things icon in the Dock or you can bring up the Things HUD (heads up display) and drop it there to get a nice link to the mail with the subject as the link text. Having the link to the mail in Things is perfect, but getting it there doesn’t work for me, since I’m a keyboard person. All my everyday tasks are keyboard centric, and I freeze when I end up at a Mac without Quicksilver, so moving overlapped windows, dragging the item and dropping breaks my flow much enough that it just doesn’t get done.

This means that I end up with two todo lists. I have one todo list in Things that contains the stuff that don’t come through the mailbox. This list is nicely organized with tags and due dates, but unfortunately it’s contains very few of my actions. These are just the things that spontaneously pop up in my head, so as you can imagine, it’s not much. The other todo list is a mail folder that I call “action” where I (with keystrokes) put all mails that needs action from my side. The problem is that it’s chaos in the action folder. It contains short term, mid term and long term things that needs action and since it’s just a simple mail folder, things are not organized neither by project, context or by deadlines. As you may imagine, this is not working well for me. I tried MailTags for a while, but then I had to send a mail to myself for the things that didn’t come from the mailbox, and that didn’t work well either. For me, a good integration between my mailbox and my GTD app seems crucial. Some people have written various scripts that are published on the Things wiki and in the forums, but they either solve a different problem than I have or hangs my Mail.app.

Since I realized this isn’t working out, yesterday evening I came to the conclusion that I need to solve this without waiting for Things to get to that feature in the priority list. As that moment, I realized I can of course solve this without Things having AppleScript support by just faking key events with AppleScript. It’s not in a nearly an as nice solution as if Things had AppleScript support (since the link text could be the mail subject instead of the raw url for instance), but at least a good enough workaround until they add it (which they said they want to do before 1.0).

So, here’s the code:

(* 
 * An Applescript to copy selected mails (from Apple mail) into 
 * the heads up display of Things.app
 *
 * http://niclasnilsson.se/articles/2008/10/12/gtd-things-and-mail
 *)

(*
 * If Things.app is not running, stop executing this script. Due to a bug
 * in Leopard(?), displaying dialogs to the user from an Apple Mail Rule
 * crashes Mail, so just silently don't do anything.
 *)
tell application "System Events" to set thingsRunning to (name of processes) contains "Things"

if not thingsRunning then
	return
end if

(*
 * Copy the url's of the selected mails to the clipboard.
 * From: http://daringfireball.net/2007/12/message_urls_leopard_mail
 * Slightly modified, removed // in the url and uppercase 3C and 3D to 
 * please Things into considering it to be a link. 
 *)
tell application "Mail"
	set _sel to get selection
	set _links to {}
	repeat with _msg in _sel
		set _messageURL to "message:%3C" & _msg's message id & "%3E"
		set end of _links to _messageURL
	end repeat
	set AppleScript's text item delimiters to return
	set the clipboard to (_links as string)
end tell

(*
 * Since Things.app don't have Applescript support, do what we 
 * would have done manually. Unfortunately, this means we can't
 * create nice links (with for instance Subject as the link text), 
 * we can only add the message url.
 *
 * My hotkey for Things HUD (Heads Up Display) is Control-Option-Space
 *)

tell application "System Events"
	keystroke " " using {control down, option down}
	--- A delay of 0.1 works on my machine, but no delay doesn't work
	delay 0.1	
	keystroke "\t"
	keystroke "\t"
	keystroke "v" using {command down}
end tell

I use the great Apple Mail plugin Mail Act-On to manipulate my mails, and if I want to move a mail to the action folder, I just press ’+’ and then ‘a’.

Now my Mail Act-On rule looks like this:

Mail Act-On rule scrrenshot

As you can see, I still move it to the action folder as well as running the script that adds it to Things, but when I get confident that this is going to work for me, I see no reason not moving the mail straight to the archive folder instead.

Here is a screenshot of the Things HUD:

Mail Act-On rule scrrenshot

If anyone find this useful and finds any improvements, I’d be glad to hear about them (blog@niclasnilsson.se) too see if they apply to my workflow as well. The only semi-major drawback for me right now is that if Things is not running, the mail will be moved anyway since that’s another part of the Mail-Act On rule, but if that gets annoying, I’ll just have the script move the mail as well to get it all within the same “transaction”.

I’ve been missing this script for a while now so maybe it can be useful to someone else (even though it seems so obvious right now, that perhaps everyone already have similar scripts but just didn’t post them on the forums).