Posted on 20 August 2008 at 7:57
So far, we’ve dumped the output from our scripts into Microsoft Word. In this post, we’ll briefly look at Apple’s Pages application, which comes bundled with its iWork ‘08 suite. Apple really improved their AppleScript support in this latest iteration of Pages.
When you want to manipulate a Pages document, you should get the document class of your document:
set doc to document 1
You can now tell doc to change the properties and elements of your document. One of the main properties of the document class is body text. Body text is the main flow of your text document. If you extract data from your database and copy that data to the clipboard, you use AppleScript to paste that data to the body text of your Pages document.
set body text of doc to the clipboard
A Pages document is also comprised of pages, sections, and paragraphs, which you can access through AppleScript.
Because Pages also acts as a page layout application, you can create and access text boxes, shapes, graphics, and images.
We’ll look at Pages more as we go forward, but you should know that Pages has an excellent AppleScript dictionary and can be used in your workflows.
Posted on 28 May 2008 at 12:34
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.
Posted on 28 May 2008 at 10:46
Let’s take a look again at our script:
tell application "FileMaker Pro"
tell database "Contact Management"
tell table 1
tell record 1
set firstName to field "First Name"
set lastName to field "Last Name"
end tell
end tell
end tell
end tell
set fullName to firstName & " " & lastName
In line 1, we have our tell statement. We’re telling FileMaker to do something for us. In line 2, we’re telling table 1 that we want it to do some work for us. You need to be careful here because you need to identify the proper table number. Fortunately, you can also identify tables by name. When you create a new table in FileMaker, you provide a name for that table. You can use this name to access it’s data via AppleScript. In line 3, we tell record 1 of table 1 that we want it’s data. Record 1 is the first record of potentially many records in the database. Within each record, we find several fields. Each of these fields contain data that we want to access. Like tables, we can access field names by name. Here, we access the “First Name” and “Last Name” fields and set them to variables. (Remember, variables are like temporary boxes that hold data.) After ending our tell statements, we create a simple concatenation of record 1’s first name and last name into a third variable identified as fullName.
Now that we have record 1’s fullName, what can we do with it? We can push it to Word or Mail or iCal or any other scriptable application. In my next post, I’ll show you how to push this data to Word.