Posted on May 28, 2008 at 12:34 pm

FileMaker to Word

Despite all the trash talk around Vista and Windows, Microsoft’s Mac Business Unit makes some of the best software for the Mac. While I prefer writing my documents in XeTeX, I often use Microsoft Word in my scripting solutions. The MacBU implemented a terrific AppleScript dictionary for Word (and the other Office apps as well) such that Word interfaces perfectly with FileMaker and other scriptable applications.

So let’s look at how we might get our data from FileMaker to Word. In our last script, we told FileMaker to get the first name and last name of the first record of our Contact Management database. In the last line of our script, we stuffed that data into a variable named fullName. Let’s put fullName into Word as we might do if we wanted to draft a letter to this person.

tell application "Microsoft Word"
	tell selection
		type text text fullName
	end tell
end tell

There are several different ways to insert text into a Microsoft Word document. With Word’s robust AppleScript dictionary, you can even access Word’s AutoText feature to insert text. In this example, we use the simplest way to insert text—we tell Word to type text. In line 2, notice that we don’t tell document 1 to do anything. In Word, you can work with selection objects and text range objects to insert your text precisely where you need it. Don’t worry about what is a selection object or text range object right now. Just know that when you tell selection, you insert text at the insertion point (i.e., the blinking cursor). On a blank document, the insertion point will be at the beginning of the document.

In our last few posts, we’ve seen how to use AppleScript to access data from a database and push it to a word processor. You can do this on your local machine. You could also access a remote database and push it to the word processor on your MacBook. Hopefully, you’re beginning to imagine the possibilities of what you can do with AppleScript. One possibility is using AppleScript to push data from FileMaker to Word templates. We’ll look at that idea in our next installment.

One Response to “FileMaker to Word”

  1. Grace Suarez on June 12th, 2008 at 19:32 says:

    Okay, I’m with you so far. This is exactly what I’ve wanted to know.

Leave a Reply