Eavesdropping on what my text editor is up to
January 23, 2012 5:54 PM   Subscribe

Is there a way to write a script that makes something happen outside of MS Word as a result of an event that occurs within Word?

I'm not actually wedded to this involving Word specifically. It could be LibreOffice or Openoffice or if it absolutely had to be, a plain text editor would be okay too.

As a simple example, say I want a pop-up box to appear once I have written 1000 words in my text document.

Or for a more difficult example, when I start a new paragraph, I want my music player to skip to the next mp3.

I have an okay knowledge of how to write shell scripts and how to code in various languages. It's specifically the bit where the script has to "watch" my word processing program and receive information from it that is baffling me.

I'm okay with a solution that only works for Linux, or only for Windows, but not one that only works for Mac.

Is this possible? What do I need to be googling to find information that will help me? I'm failing at google because all I'm getting is how to script things within Word, and how to write screenplays.
posted by lollusc to Computers & Internet (6 answers total) 3 users marked this as a favorite
Yes. Look at the Application object in visual basic for applications. So to start something in Excel from Word you'd call Excel.Application

Not all programs are accessible in this way, but if I remember correctly, you can call programs using the Explorer object.

PS These memories are 5+ years old and could be outdated.
posted by Pants! at 6:19 PM on January 23, 2012

Yes, what Pants! said. You can do all of that within word. You can use COM automation to literally do anything the computer is capable of doing in response to events in Word. Office (and most of Windows) go to great lengths to make things automateable. If you get stuck, you can ask specific question (here's what I tried, it didn't work, how do I make it work) on StackOverflow.com and get quick responses. There is a huge community around this sort of stuff.
posted by jeffamaphone at 6:47 PM on January 23, 2012 [1 favorite]

Awesome. Thank you. Visual Basic is something I have generally been able to avoid until now, but I guess I'll have to bite the bullet :)

Any suggestions for good sites for tutorials that might be of use here?
posted by lollusc at 8:18 PM on January 23, 2012

(I don't mean general tutorials on Visual Basic. I can probably muddle through there. I mean tutorials involving things specifically similar to what I want to do. Or COM automation in general.)
posted by lollusc at 8:21 PM on January 23, 2012

I'm not aware of the best sites anymore, but one way I learned was to first read or study the concepts behind object oriented programming, and then use the record macro and debug macro features. The record macro writes the code for you, then the debug steps through the code one line at a time so you can see what it's doing.
posted by Pants! at 6:37 AM on January 24, 2012

Thanks. I'm fine with OOP, but using the record macro sounds like a good way to learn VB specific things that I hadn't thought of.
posted by lollusc at 4:01 PM on January 25, 2012

« Older Argh help me deflect questions about my health at...   |   Another search for a lost childhood movie Newer »
This thread is closed to new comments.