Pages + AppleScript Challenge


As many of you know, Scrivener cannot import .pages files because Apple don’t make the .pages format public and don’t provide an importer or exporter. This surprises some new users (and even on occasion outrages them), who don’t necessarily realise that it’s up to Apple to make the format available to third parties.

I’m been pondering this, and I even went so far as to write an importer that hacks the QuickLook preview of .pages documents, but this broke with Pages '09. Now it occurs to me that this could be solved with an AppleScript. The problem, though, is that my knowledge of AppleScript goes something like this:

tell KB
set knowledgeOfAppleScript to iHaveNoIdeaWhatIAmDoing
end tell

Literally, “tell” and “end tell” is about my limit. So, here’s your opportunity to earn a free update to 2.0 (or a free 1.x licence if you don’t own Scrivener already). All you have to do is write me a simple AppleScript that will do the following:

• Open a list of .pages files passed to it, one by one, in Pages.
• Export each file to RTFD format in a folder specified in the script (not the Desktop).

That way, I can save this script as an application and pass any .pages files to it to create some RTFD files that Scrivener can import. (Obviously I’ll need to warn the user that Pages is about to open, etc.)

Note that I’ve tried fudging the above with code found on the web, and it seems that you can’t export to RTFD via AppleScript - you just get an error message. But Pages does support RTFD export - if you have a file containing images and go to export as RTF, Pages actually exports to RTFD. So it may just be that I didn’t know what I was doing. But if it’s not possible to export directly to RTFD, you can copy the “body text” of the open Pages document, and you should then be able to copy that into a TextEdit window and save that as RTFD.

The reason I’m asking for RTFD is that it supports images, whereas RTF does not - although unfortunately copy and paste seems to lose footnotes, whereas a direct export to RTFD would work.

Any help with this much appreciated!

All the best,

Here are some leads. It looks like there are some viable scripts out there already. This one does everything but RTFD. Given the range of format options supported, it makes me wonder if Pages’ AppleScript suite has support for RTFD at all. According to this blog post, you can get at the supported formats following these instructions:

According to the descriptions on both of these posts, it looks like Apple changed the naming convention in Leopard, meaning scripts developed for 10.4 will not work on 10.5 and vice versa (though perhaps AppleScript can detect OS version and modify itself? I’m equally clueless when it comes to AS).

I don’t have Pages, so I cannot investigate the RTFD gap.