Things Mail Script

ThingsRecently I have been trying to be more focused on the stuff that I need to get done. Just like everyone, I have email, phone calls and such that lead to things that I have to get done. I seemed to be doing ok with most of them, but emails were getting lost in the sea of stuff that I received every day. I read this post from Michael Hyatt and thought that I would give inbox zero a try.

So to get to inbox zero I had to employ some tools to help make this happen. The rule is that if you can deal with the email within two minutes, just get it done. If not then it becomes a task. OS X doesn’t really have any good tools to handle tasks and nothing at all that would sync with the iPhone. I don’t want to go into the details of of my choice, but I ended up with Things on the desktop and iPhone.

I’m a distracted person and for me to keep up with a system it has to be easy. I quickly get frustrated by software not being integrated so I go back to my same old ways. If this was going to be successful I would need to implement some apple scripts. Two keystrokes is what I needed. If I had handled the email I need a command to move the message to my “All Mail” folder and if not another command to create the task. Things has extensive Apple scripting support so I was on my way. I found some sample code in the Things Wiki and modified it to suit my needs. I will put the code for the scripts at the bottom of this post.

Come to find out the scripting was the easiest part of this project. It was harder to find a way to run the script from a keystroke. During my research I keep coming up with MailActOn which I downloaded and it did the trick, but I just couldn’t bring myself to purchase it. The only feature I needed was the keystroke mapping and thought there had to be an open source solution to my problem. After digging deeper into Google, I found out that the swiss army knife of Mac software, Quicksilver, could solve my problem. I’m not going into the detail of how to set it up in this post, but with a little research I was up and running.

I have been working with this solution for about a month and so far I have really liked it. Of course the scripts only work on my laptop and not on the iPhone, but with copy and paste in iPhone 3.0 I have survived. I hope that the Things people add a way to create a to do from a mail message on the iPhone.

Move Message To “All Mail” Folder Script:
At some point I’m going to update this script to move multiple selected messages, but right now it only moves one.

tell application "Mail"
set theSelectedMessages to selection
set the selected_message to item 1 of the theSelectedMessages
set currentMailbox to the mailbox of the selected_message
set currentAccount to the account of the currentMailbox
set filedMailbox to "All Mail"
move selected_message to mailbox filedMailbox of currentAccount
end tell

Create A To Do And Move The Message To “All Mail” Folder Script:
tell application "Mail"
set cr to ASCII character 13 -->You can probably use the Unicode Equivalent but I didn't know it and this worked right away.
set LF to ASCII character 10 --> Same as here
set carriage_return to (cr & LF as Unicode text)
set theSelectedMessages to selection
set the selected_message to item 1 of the theSelectedMessages
set message_id to the message id of the selected_message
set message_url to "message:%3C" & message_id & "%3E"
set TheSubject to the subject of the selected_message
set theBody to "[url=" & message_url & "]From: " & the sender of the selected_message & " - Subject: " & TheSubject & "[/url]"
tell application "Things"
show quick entry panel with properties {name:TheSubject, notes:theBody}
end tell
set currentMailbox to the mailbox of the selected_message
set currentAccount to the account of the currentMailbox
set filedMailbox to "All Mail"
move selected_message to mailbox filedMailbox of currentAccount
end tell

* Updated after an error was found

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.