Keynote

From nswccWiki

Jump to: navigation, search

Live Keynote

Keynote is Apple's presentation software "designed for Steve". Keynote can be driven by AppleScript making it very powerful.

I wanted a slideshow of a rotation of 5 slides, but with one particular slide showing the current time. The purpose was to use it as a Science Fair welcome/ program guide using a data projector, as an unattended kiosk. Yes, it could very easily be done using web pages, but this is to demonstrate the principle.

Firstly, you design the slideshow, making sure that on the slide you want to be updated, the main text field called *body* is left blank but properly formatted for a time display. Secondly, open the slideshow file. This simplifies the script. It does not have to be running. Run the Applescript below.

AppleScript will plant text in the field when it is not displayed, but while the slideshow is running. If you set up the slideshow as a loop, and then start the slideshow using the simple AppleScript below, the two will (co-operatively) interact. The behaviour can become quite complex. An example plants the current time as "<hh:mm> [AM|PM]" in the body text field of slide 3 in a rotation.

-- Live Keynote, Ian W. Parker - vers 0.2 (updated)
-- first worked on: 2009-08-12, last worked on: 2009-08-06
-- works best if the slides display for say 30 s or less at a time
-- we could control the whole show from here but we let
-- Keynote internally do some of the hack work

tell application "Keynote"
	tell slideshow 1
		start
		repeat
			delay 2 -- seconds.  This script does not need to run faster
			set the_time to current date
			set the_time to time string of (current date) -- get now()
                        set the_time to every word of the_time -- slice
                        set the_time to item 1 of the_time & ":" & item 2 of the_time & " " & item 4 of the_time -- extract fields
			-- plant the current time (while not being displayed) in slide 3
			set body of slide 3 to the_time as string
		end repeat
	end tell
end tell

Speaking of Keynotes

Most people know that a slide presentation (usually) consists of a series of slides that are shown by a presenter who manually switches the slides and "speaks to the slide content". Duh! It is possible to also set up an automated slideshow usually without narration. But it is possible for Keynote to generate and perform the whole thing, including narration, (almost) unaided.

That's right the presentation is done entirely by the computer- including speaking! Most people would think that this is done by recording a sound track and playing it as you select the slides. Well, yes you could do that, and you could just simply record the whole thing as a Quicktime movie. There is a more interesting approach.

Keynote (along with Powerpoint Presentation Manager) can have presenter notes embedded in them. In the case of Keynote the "container" is called notes. You can write the notes, and then access them using AppleScript and Applescript has a command that is called "say .."

The idea is:

  • write the presentation as a sequence of slides
  • write a narration for each slide, and place it in the notes field.
  • run the slideshow using an Applescript that treats the notes as narration text (using text-to-speech technology built into each Macintosh).

You will need a Keynote file open but not running. You will also need to put some text in the notes field (these are usually for the presenter to read, but in this case becomes what the 'presenter' says), The style should be as for a narration of a podcast - short sentences, no more than one connective and with pauses. Separating each sentence with blank lines works well.

Next you run the script shown below. This will start the process. You have to be careful about how it runs because of the lack of sophistication. The slide transitions (to the next slide) are performed by a manual press of the command key (left or right of the spacebar). This allows you to pause (for example, if you want students to copy information) at the end of the narration for each slide. It also ensures that the normal transition triggers (e.g.. spacebar, mouse button, right arrow key) don't interfere with the process. No other special considerations are required. It would be a great way to "think different" about presentations, and perhaps get an idea of how to pace a narration. Most people tend to want to speak too quickly and using sentences that are too complicated, as if in a conversation.

Obviously, there are issues, especially with intonation, pace and correct pronunciation, but it's an interesting approach. It would be nice if Apple would integrate an AppleScript entry in the Keynote dictionary, that would actually reduce this script to a few lines but until then …


Here is a short Applescript to get you started. But first download Extra Suites app.

-- Ian W. Parker First worked on: 2010-01-02 (palindromic!) last updated : 2010-01-03
-- and speak the notes in each slide, then you *manually* move on to next slide
-- duration of slide is at least time of the narration
-- requires faceless application: 'Extra Suites' to be installed to detect command key press
try
	tell application "Keynote"
		-- allows us to queue up the slide show.
		start from current slide of slideshow 1
		set start_slide to (slide number of current slide of slideshow 1)
		-- this is a bit too automated but works
		repeat with next_Slide in every slide of slideshow 1
			if slide number of next_Slide is less than start_slide then
				-- skip
			else
				-- do normally		
				tell slideshow 1
					show next_Slide
					set narration to the notes of current slide
					say narration using "Alex"
					-- we halt the processing until we click on the mouse
					-- to allow for us to programmatically pause the show
					tell application "Extra Suites"
						repeat until (ES command down)
						end repeat
					end tell
				end tell
			end if
		end repeat
	end tell
on error
	--
end try