views:

1080

answers:

2

There is a rich scripting model for Microsoft Office, but not so with Apple iWork, and specifically the word processor Pages. While there are some AppleScript hooks, it looks like the best approach is to manipulate the underlying XML data.

This turns out to be pretty ugly because (for example) page breaks are stored in XML. So for example, you have something like:

... we hold these truths to be self evident, that </page>
<page>all men are created equal, and are ...

So if you want to add or remove text, you have to move the start/end tags around based on the size of the text on the page. This is pretty impossible without computing the number of words a page can hold, which seems wildly inelegant.

Anybody have any thoughts on this?

+1  A: 

I'd suggest that modifying the underlying XML file is "considered harmful". Especially if you haven't checked to see if the document is open!

I've had a quick look at the Scripting Dictionary for Pages, and it seems pretty comprehensive; here is part of one entry:

document n [inh. document > item; see also Standard Suite] : A Pages document.

elements

contains captured pages, character styles, charts, graphics, images, lines, list styles, pages, paragraph styles, sections, shapes, tables, text boxes.

properties

body text (text) : The main text flow of the document.

bottom margin (real) : The bottom margin of the publication.

facing pages (boolean) : Whether or not the view is set to facing pages.

footer margin (real) : The footer margin of the publication.

header margin (real) : The header margin of the publication.

id (integer, r/o) : The unique identifier of the document.

...

So, I guess I'd want to know what it is that you want to do that you can't do with AppleScript?

Matthew Schinckel
A: 

The latest version of iWork '09 includes very comprehensive, although not complete, Applesript hooks, especially for pages. The us of Applescript should be much safer and more stable than modifying the underlying file.

Ian Turner