A little Python program to create to-dos in Things from a template file

August 30, 2010


I quite like the to-do list manager Things from the company Cultured Code. (Like plenty of other people, I expect, I'm waiting for repeating to-dos on the iPhone version, but even without that feature it's far the best one I've seen.) I also have a list of things to do in preparation for going on a trip that I've refined some over the years. (Make sure I have enough books, get any foreign currency I'll need, get a hostess present, etc.) Since some of the items on the list may require that I wait for something to be shipped or for other people to do things, I have various indications in the list of how long before I leave that I ought to begin each item.


I've sometimes thought that it would be convenient if Things could make use of that list without my having to go to the trouble of entering each item. That's the sort of thing that computers are meant to do, after all. I thought of emailing the folks at Cultured Code and suggesting a feature of that sort. And then I noticed that the Macintosh version of Things can be controlled by AppleScript. And there's a Python module that can send the necessary events (so I didn't have to figure out much about AppleScript). So I hacked up a little Python program to read my file and create the appropriate to-dos in Things.


It's unimaginatively called todosfromfile.py and it's licensed under the GPL. You can get it here.


The file it reads has two sorts of lines: "time-before" lines and to-do lines. The time-before lines specify how long in advance the subsequent to-dos should be due. So the file might look like this:


1 month

Make sure I have the clothes I'll need


2 weeks

Get books

Get hostess present

Foreign currency


1 week

Program phone with addresses

Make sure I have enough cash


2 days

Get weather forecast


1 day

Check in


On day

Pack laptop, chargers


Blank lines and lines beginning with a "#" are ignored.


The program creates a project in Things and adds the to-dos to it. It's run from the command-line and takes three arguments: the name of the template file (--file), the name to give the project (--name), and the date to count backward from (--date). The date needs to be in YYYY-MM-DD format. So I might run it as:


$ python todosfromfile.py --file trip.templ --name 'Trip to Maine' --date 2010-10-31


It requires the Appscript library and Python 2.7. It only needs Python 2.7 because I used the argparse module and that could easily be changed.