Apr
28
2007

Scripting the Milk: Powering Outlook from Groovy

I’ve always been a TODO list kinda guy and the only product that I’ve found works well with my PocketPC is Outlook. That’s cool when I’m on client sites (since they all run Outlook), except that I’d like to be able to use some other tool when I’m hacking away on my Macbook.

Well lately I’ve been tinkering with Remember The Milk to see what online TODO managers have to offer. I think RTM is even built by a bunch of Aussies, so it gets extra points. The only thing it doesn’t do yet is Outlook integration… But they do offer a pretty comprehensive REST-based API. You know where I’m heading with this right? How hard could it be?

Ok, so a little bit of XmlSlurper action from Groovy and I’m all set and parsing out my tasks straight from RTM method responses. But how am I going to get to my Outlook tasks? Outlook has got some kinda COM story going on…

I’ve used JNIWrapper in the past for getting to COM based stuff, and it works just great – but the upgrade prices were starting to hurt, so I checked out com4j. Very neat little project – and an almost entire replacement for JNIWrapper. Pointed it at my outlook tlb file and voila! Full set of Java classes to match with Outlook… but then I remembered that Guillaume had done some funky Groovy/COM library that he wrote up for Groovy In Action. Grabbed my copy of GINA and checked it out…

Enter Scriptom. This is the COM integration library that I’ve been looking for. No need to generate any classes, just give it a COM object and start calling methods. Takes advantage of Groovy dynamic typing goodness to make it all very easy.

Need to get to your Outlook tasks? Howse about something like:

import org.codehaus.groovy.scriptom.ActiveXProxy

def outlook = new ActiveXProxy("Outlook.Application")
def namespace = outlook.GetNamespace("MAPI") 

def taskFolder = namespace.GetDefaultFolder(13) // tasks
def tasks = taskFolder.Items

for (i in 1..tasks.Count.value) {
	def task = tasks.Item(i)
	if (task.Complete.value == false) {
		println task.Subject.value
	}
}

Sensational. I’m now in a position where I can get my list of Outlook tasks, and my RTM tasks… now the tricky bit around doing the merge. Both support a “last modified” attribute, so it should be ok to handle the actual time mods, but I’m still not sure how I’m going to handle task renames? I guess I’ll need to tag the RTM entries with an Outlook task id… That could get interesting…

Anways, double thumbs up to Scriptom. Guilluame has done some sensational stuff there. Will post some more when I’ve got something working…

About the Author: Glen Smith

3 Comments + Add Comment

  • Great post. I’ve done a project in JACOB for interfacing with Microsoft Word, Excel, etc, and the Scriptom library actually comes bundled with JACOB. The code is much lighter, and there’s even ways to get IDEs such as NetBeans and Eclipse to work with Groovy. Kudos to your struggles.

    -Tres

  • Hi Glenn!

    First off, congrats on the book. A phenomenal effort. I absolutely love it!!!

    Now, I was trying to do something similar to what you’re doing (trying to sync RTM with Outlook). What API have you used to add/remove/update tasks in Outlook. I was able to get a list of tasks available in my Outlook using Groovy and Scriptom, but I can’t seem to find the correct API to do CRUD on the tasks.

    Cheers,
    -Kodeninja

  • @kodeninja From memory all the crud stuff was all collection based (eg. tasks.sometask.remove() or tasks.add()). If you get stuck, drop me an email and I’ll see if I can dig up the source for the Outlook stuff. Would love to see it re-used somewhere!

    Don’t forget to check out http://kenai.com/projects/groovyrtm for a Groovy API to the RTM side, too!

    Glen.
    (oh. and thanks for the book comments! Glad you liked it!)

Leave a comment

Glen Smith

About Glen

Co-author Grails in Action