Today I achieved what some might consider to be a rather simple milestone, but it is quite exciting for me none the less. I was able to access a COM object using python. More specifically, I was able to create an object for my windows screen reader, Window-Eyes, and make it speak something using the python interpreter. Let me explain precisely how I did this, because it is extremely cool! In windows, many programs have an object model of sorts with which you can communicate to provide enhancements to the application in question. Many main stream applications such as Word, Excel, iTunes and Skype have object models so you can alter or provide your own functionality to the program. This adds extreme flexibility to the program, because script writers now have a way to tailor the software to better meet their needs. Most screen readers are no exception to this rule, although there are a wide variety of implementations depending on the screen reader. The Window-Eyes screen reader happens to be a COM server which can be accessed the way you would access any other COM server. From what I understand, COM is somewhat of a standard in Windows. Before we get started with this example, you will need to grab a few things from the internet, assuming they are not installed already. You will need Python of course, but hopefully that’s a given. The next thing you’ll need is the pywin32 extensions for python. This is a library of modules that are useful if you plan to be writing lots of python scripts or applications under Windows. The win32 extensions purportedly works with Python 3.1.2. However, when trying to install it for 3.1.2 I received an error that python 2.6 was required. As I didn’t feel like trying to figure out why I was getting that error, I have temporarily rolled back to version 2.6.5. Once everything is installed, let’s open up the python interpreter by the usual means, or you could simply create a new script using your favorite text editor. Type the following lines.
# begin example script
# shows how to get a COM object and access some of its properties and methods.
weObj = win32com.client.Dispatch(“WindowEyes.Application”)
# speaks the string that is passed to the speak method.
As you might have guessed, I immediately heard the phrase “hello world!” spoken by the active speech synthesizer used by Window-Eyes. How cool is that?! A useful application of Window-Eyes scripting, or indeed screen reader scripting in general is to enhance the accessibility of applications that do not work right out of the box. I have already done this using other languages, mostly JScript, but the nice thing about COM is it supports a wide variety of programming languages.
One of the reasons I bring this up here aside from the fact that it is really cool and very relevant to our project, is that we are always looking for potential script writers for Window-Eyes so that more programs can become accessible. If you know python, half the battle is over; it’s simply a matter of learning the Window-Eyes object model, which is well documented.
I have only begun playing around with COM objects using python, so I am hoping to get further with this in the weeks to come.