Things Inbox Zero AppleScript

If you practice Inbox Zero, you probably know how hard it can be to get on track if you slip up for even a short period of time. This is especially true if you live out of a GTD program like Cultured Code's Things and treat it as your primary inbox with email being a noisy secondary inbox that just keeps filling itself whether you like it or not. Processing your email inbox back to zero after you've let it go for a while can take a great deal of time. Because of this, I wanted an early warning system for when my email was starting to get out of control. I devised the following AppleScript that creates a Things to-do whenever my email inbox has more than a certain pain-inducing threshold of messages sitting in it:

set emailLimit to 50
set mailBoxName to "INBOX"
set mailAccount to "Personal"
set toDoList to "Today"
set toDoProperties to {name:"Process personal email to Inbox Zero"}
set tagNames to "Home"

tell application "Mail"
    if the (count of messages of mailbox mailBoxName of account mailAccount) ≥ emailLimit then
        tell application "Things"
            try
                set todo_things to to do named (name of toDoProperties) of list toDoList
            on error
                set newToDo to make new to do with properties toDoProperties at beginning of list toDoList
                set tag names of newToDo to tagNames
            end try
        end tell
    end if
end tell

This script is for Apple's Mail.app and Cultured Code's Things.app, but the concept could obviously be adapted to other email and GTD applications that support AppleScript. I've put all the relevant settings at the top. Here is what they mean:

  • emailLimit: Your pain threshold. If you have at least this many email messages, the to-do is created.
  • mailBoxName: The name of the mailbox on the server to inspect. For Gmail accounts, it's INBOX.
  • mailAccount: The name of the account you set up in Mail.app.
  • toDoList: Where to create the to-do.
  • toDoProperties: Set the text of the to-do and possibly other properties.
  • tagNames: You can tag it!

Paste this script into the AppleScript Editor, customize the settings at the top, and then save it in the following location: ~/Library/Application Scripts/com.apple.mail/

You then need to create a rule in Mail.app that will run the script every time you get an email. Here are the steps for that:

  1. Open Mail.app's preferences under the Mail→Preferences menu item.
  2. Go to the "Rules" tab and click "Add Rule".
  3. Name your new rule "Inbox Zero" or whatever you want.
  4. Run the AppleScript on every email in an account by making a rule that looks like this:

    • If "any" of the following conditions are met:
      • Account / (the account name which you will also set in the script as mailAccount)
    • Perform the following actions:
      • Run AppleScript / (the name of your script)

If you have multiple email accounts, you'll need a script and rule for each account.

Posted on Jan 22, 2013
Written by Emlyn Murphy