Keynote Scripting and Automation

I don't think this breaks the Terms of Use. If it does, moderators please delete this. 🙂

As some of you may know, I've experimented with writing plugins to extend Keynote's capabilities in the past. These plugins included a rough AppleScript plugin for Keynote 1, before Apple released rudimentary AppleScript support in Keynote 2. I've been dragging my feet on writing a new AppleScript plugin for Keynote 2, but with the recent activity in Jeff Ferrell, "XML Slide Generation Possibilities?", 10:35am Jun 27, 2005 CDT about automating the replacement of text and images, I can see that many people would like to be able to come up with custom workflows to automate the creation and modification of Keynote presentations. So, I've decided to dedicate some time to write a new AppleScript plugin for Keynote 2 along with Automator actions to make it easy for people to use. My questions to anyone interested are:

  • If you are an AppleScript coder, what classes/properties/commands would you like to see?
  • If you are an Automator user, what actions would you like to see?
  • How would you feel if the AppleScript + Automator package was released as shareware? Would $10 to $15 be a reasonable price range?


These questions aren't just hypothetical, the work's already been started!

For AppleScript experts, you can download this sdef file to see the classes and commands that have already been implemented (in the Keynote Additions suite).

For Automator users, here's a list of the actions I've thought of so far:

Getting Items


  • Find Keynote Items (slideshows, slides, visuals)
  • Filter Keynote Items (slideshows, slides, visuals)
  • Get Specified Keynote Slides (by exact selection, index range, or index)
  • Get Keynote Visuals


Working with Slides


  • New Keynote Slide
  • Move Keynote Slides (by absolute or relative position)
  • Modify Keynote Slide Title (content, visibility)
  • Modify Keynote Slide Body (bullets, visibility)
  • Replace Keynote Slide Text (scope by key, class or pattern)


Working with Visuals


  • New Keynote Visual
  • Modify Keynote Visual (height, width, x position, y position, angle, horizontally flipped, vertically flipped, opacity, locked)


(Currently supported visuals are image, line, shape, title and body)

My intention is to release this by the end of this month or early next month. This will be followed by a second plugin dealing with iMovie/iDVD export, but I'll cover that in another thread later. I'd greatly appreciate any feedback (good or bad) on the posted questions, and anything else about this project.

Thanks in advance!

Posted on Jul 8, 2005 11:16 PM

Reply
58 replies

Jul 9, 2005 8:00 AM in response to King Chung Huang

Ah, good to see somebody picking this up in earnest! 🙂 Something I've run into that you may want to consider, if you have some sort of functionality that inserts text into a slide from an outside source:

For myself, I've had to write a (pretty rough) function to truncate text to fit in a specified area by trimming sentences off the end. In my case, it's text that's written in a sort of journalistic style, so shaving a sentence or two off the end doesn't really diminish the content at the beginning...

In other cases, I've just let the text spill over the slide, and decided I'd go in manually and clip it to fit, adding the overflow onto additional slides. (Finding the "end" of a "sentence" turned out to be a lot more complicated than I was prepared to deal with at the moment...and I didn't want to trim by word alone.)

Anyway, in an ideal world, I'd give myself the option, if I were inserting a paragraph of text onto a slide, to:
* re-size text to fit text area
* truncate text to fit text area (with a set font size)

If I chose to truncate, then I'd either want to

* trim by nearest sentence boundary
* trim by nearest word boundary

and then

* discard overflow
* duplicate slide and insert overflow (repeat until done?)
* choose a new slide master and insert overflow

Whew! How's that? This stuff might already be included in what you've mentioned above--just wanted to be sure to at least bring it up!

I haven't messed with Automator that much yet; just haven't found a reason to. Something like this might give me one, though. (And $10-$15 usually seems reasonable to me. 😉

Jul 16, 2005 11:26 AM in response to Brian Peat

The AppleScript functionality acts directly on the in-memory state of the presentation, not the XML. So no reloading of XML is necessary to modify slides.

That said, I've been unable to get slide modifications to appear while a presentation is running. I just tried writing a simple script that continually increments a number in the title of a slide. During a full screen presentation, the displayed title doesn't seem to change no matter how I navigate to it. However, when I exit the presentation, I can see the change occurring on the slide. I'm guessing the full screen presentation either renders the slides out and just reuses the cached image, or is making a copy of the slide data and presenting with that. I'll play around with the fullscreen controller today and see if I can find out how it works.

Jul 16, 2005 4:48 PM in response to King Chung Huang

As an addenum, it's much easier to have content updated and displayed the next time a slide is visited, like J.C. Burns was asking about. I'm haven't found a reliable way to update a slide immediately if it's past its first build. Maybe this should all be some sort of option (like Brian was suggesting).

For the curious, here's the script that was used. It won't work without the Applescript plugin, but you can see how the title was updated.

<pre>repeat with i from 1 to 10
tell application "Keynote"
set content of title of slide 1 of slideshow 1 to (i as string)
say i
end tell

wait(5)
end repeat</pre>

Jul 17, 2005 9:42 AM in response to King Chung Huang

I think having a way to automatically have a presentation point to and start another presentation (without having to click on a hyperlink) would be good too. I haven't tested in awhile, but I thought that if you opened both presentations before you started the first one, the hyperlink between the two wasn't noticeable. That might be a way to get around the "cached display" limitation.

Jul 18, 2005 11:05 AM in response to Kyn Drake

I did find a way around the cache problem as you can see in the movie. I just had to tell the controller to invalidate the cached copy of a slide after an update.

As for automatically starting another presentation without having to click on a hyperlink, would an Automator action that let you pick several presentations to show in order be acceptable? Or, is there a specific need to set the automatic switch inside of a presentation?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Keynote Scripting and Automation

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.