Late last year, Apple generated a wave of negative press after releasing slimmed down Mac versions of the iWork apps – Keynote, Numbers and Pages. Rewritten from the ground up to focus on ease of use, consistency, and iCloud support, the apps lacked lots of the useful productivity features that Mac users had come to use. One major setback was a significant reduction in AppleScript support, a problem for anyone attempting to automate an iWork-based office workflow.
Apple, however, moved quickly to address growing concern, acknowledging the missing features and committing to return many of them in subsequent iWork updates. Some of the promised enhancements included AppleScript improvements in both Keynote and Numbers (curiously, AppleScript improvements in Pages weren’t listed).
Some were sceptical whether these enhancements would come to be but, lo and behold, in January, Apple began making good on its promise. A seemingly minor Numbers update reintroduced nearly the entire suite of Numbers ’09 AppleScript terminology. This update restored many existing Numbers scripts to working order and reinstated the ability to write new ones. The release was a welcome step in the right direction, but there was more work to be done, especially in Keynote and Pages. I’m pleased to say that this week, Apple has delivered again. This time, the iWork apps have received a notable set of AppleScript improvements across the board.
Like Numbers, Keynote now includes a compatibility suite of scripting terminology, returning much of its previous scripting support. This means that some existing Keynote scripts may begin working again, although it’s likely some tweaks will be needed. Keynote also adds a variety of new scripting features, including better export options and access to extensive slide attributes, such as transitions and presenter notes. With this release, you can write scripts that build entire Keynote presentations from scratch, manipulate slides, play and control slideshows automatically, convert presentations to movies, and lots more.
Enhancements in Pages allow you to write scripts that create new documents based on application or user templates, perform find and replace operations on text (think Mail Merge), add and manipulate content, and even export documents as encrypted PDFs. Pages doesn’t include a compatibility suite like Keynote and Numbers, possibly because its overall functionality has changed so much that one isn’t applicable. So, if you have existing Pages scripts, the odds are good you’ll need to rework them a bit to get them up and running again.
Even Numbers includes some scripting changes above and beyond what was added in the last update. You can now create template-based documents, export in different file formats, and interact more extensively with tables, charts, and other elements.
However, the most exciting news is that Keynote, Numbers, and Pages all introduce brand new text and iWork suites of terminology, allowing for interaction with text and common elements such as charts, images, tables, lines, placed audio files and more.
What’s especially interesting is that these suites are consistent from app to app. In other words, since all the apps have certain features in common, the same exact AppleScript terminology is used to script those features. This is huge: it means that if you write a script that builds a table or chart in Numbers, you can change the app name in your code to Keynote and your script should ‘just work’ in Keynote. Want to add an image, replace some text, change the volume of every movie in a document? The code you write is the same for any of these tasks, regardless of which app you’re targeting. Of course, app-specific features still have their own custom non-shared terminology; for example, Pages doesn’t have terminology for working with Keynote slides or entering presentation mode.
The universal approach that Apple is taking with a shared scripting implementation is truly awesome, as it makes learning how to automate the iWork apps easier and allows for more modular, reusable code. Its implementation couldn’t have been easy, and Apple’s iWork development team deserves a lot of credit for pulling it off. The iWork apps are presumably built by different sets of developers, and I’m sure it required lots of close collaboration, planning, and attention to detail to generate shared consistency at this level. I’d love to see more developers embracing scripting language consistency like this.
Even the iWork AppleScript dictionaries themselves received some useful improvements, aside from just displaying the new terminology. They now include formatted HTML-based help content and example code snippets. Although the implementation of these features is pretty limited at this point, it’s hopefully a sign of more to come in later releases. If you’ve ever tried to decipher a cryptic AppleScript dictionary, I’m sure you’ll be excited about this prospect.