Scripting Word

Now, this is weird. My more recent tasks have involved working with both the Word testers and the automated testing group to iron out some ways that we can improve on testing. In particular, now that Word has a more complete AppleScript implementation than previous versions, we can move from automated testing based on VBA (Visual Basic for Applications) to automated testing based on AppleScript.

Up until now, I’ve dabbled in AppleScript, but as someone accustomed to more conventional programming languages, I’ve found AppleScript to be a wee bit inscrutable. It’s unfortunate that there really is no standard implementation of, say, the Text suite such that one way of doing things with, say BBEdit, might also work with something else, like CodeWarrior’s IDE. Alas, AppleScript dictionaries don’t quite measure up to VBA’s object browser.

This is particularly difficult for me, because I have some preconceived notions of how a text editor should be automated. More than simply the fact that I’ve worked on Word for a few years, I was one of the team members who implemented the original object model for Word’s implementation of VBA. I did all of the table-based objects, and the paragraph formatting object (including some work with styles). I also did a good deal of work on the underlying plumbing that routes certain methods and properties through Word’s normal command dispatch mechanism (i.e. the code that runs when you do something like select “Font” on the “Format” menu).

Anyway, when it comes to AppleScript, I’m definitely in learning mode. So, I’ve been googling a bit about AppleScript, and what do I run into but John Welch’s very excellent piece about AppleScript and KeyChain, which happens to begin with a link to my Anatomy of a Software Bug. And, yes, John, Paul Berkowitz is a genius. There’s a reason Matt Neuburg devotes almost an entire paragraph of his acknowledgements in AppleScript: the Definitive Guide to Paul. (And, no, Paul, I haven’t forgotten the question you asked about typography in Word and the possibilities for improvements. I’m wrestling with just how much I can talk about at this stage of the game. As my father would say, when in doubt, mumble.)

But the genius I want to call out today is Jim Murphy. While the rest of us were busy enhancing our applications from the user’s point of view, Jim, almost single-handedly, put together the AppleScript implementations for Word, Excel and PowerPoint. I’ve spent the past couple weeks sanding off some of the rough edges (particularly the Style object), but the sandpaper I’m using is very fine-grained due in no small part to just an incredibly outstanding job that Jim did on this enormous effort. While I shan’t fail to acknowledge the role Paul Berkowitz played in helping define how the implementation should behave, for which AppleScript programmers around the world owe an eternal debt of gratitude, Jim is the person who made it happen.

If you’re doing anything having to do with trying to script Word 2004, I want to hear from you. You can add comments here, but you can also get in touch with me by clicking on the “Contact” link in the “My Links” list in the left-hand column of the web page that has this article. I’ll also be attending WWDC this coming week, and you’ll probably find me in some of the scripting sessions.

I want to hear both the problems and issues you’ve encountered as well as some of the successes you’ve had. I want to know both the things you’ve found difficult and the things you’ve found to be easy.