Applescript or Automator to create Keynote presentation from text file

Newbie here. Thanks for looking.

I need to import a text file (consisting of subtitles) into a Keynote presentation. I need to turn each subtitle into a single slide, interspersed with blank (black) slides. I’d like to create an Automator action in order to do this.

I think the way to do this is to filter paragraphs ending in two line breaks, but I don’t know how to do it.

Thanks a lot for any guidance.

Hi Silks,

Using code I once found on the internet, I wrote a sample script for you, which might point you in the right direction. Please note that scripting Keynote is not easy. I tested the script with Keynote 4.0.3 on Mac OS X 10.5.5.


set filepath to ((path to preferences folder from user domain) as Unicode text) & "com.apple.mail.plist"
set contlines to paragraphs of (read (filepath as alias))
tell application "Keynote"
	launch
	-- activate
	set allthemes to name of appThemes
	set usetheme to choose from list allthemes
	if usetheme is false then return
	set usetheme to usetheme as Unicode text
	-- other slide size...
	-- {800, 600},{1024,768},{1280,720},{1680,1050},{1920,1080},custom...
	set themeprops to {theme:usetheme, slideSize:{800, 600}}
	set newslideshow to make new slideshow at end of slideshows with data themeprops
	repeat with contline in contlines
		tell newslideshow
			set newslide to make new slide
			tell current slide
				set body to contline
			end tell
			-- insert black slide
			set newslide to make new slide
		end tell
	end repeat
end tell

thanks, martin, for taking the time to answer!
the script isn’t quite there yet, but it’s a step in the right direction.
first of all, why does it use my mail prefs file? did you just choose it arbitrarily?
that aside, there are several larger issues:

  1. it uses “paragraphs”, which apparently means anything that ends with a line break. what i actually need is everything that ends in TWO line breaks. with subtitles, not all line breaks indicate a new paragraph, because some subtitles are one line long and others are two lines long.

  2. the text i’m trying to convert is in hebrew. using this script on my file converted all the text into some kind of gibberish (example: \uc0\u1488 \u1504 \u1495 etc.) i tried again with an english language file, and the text arrived in keynote intact (albeit badly formatted). the file i’m reading from was written in hebrew in apple’s textedit and saved as an rtf.

  3. the inserted text was also preceded in each slide by a bullet, and in the middle of the slide. i need no bullet and at the bottom.

like i said, i am inexperienced and don’t really know how to fix these issues… hope you (martin) or someone else here can devote some of their valuable time to help perfect this script.

I just used this file, as it is available on most Macs :smiley:

Maybe you can solve this problem by using AppleScript’s text item delimiters.

A RTF file does not only contain the raw text, but also special markup tags in order to save the text style (bold, underlined, etc.). Therefor you will need to convert the rich text file into a plain text file, if you want to read it in with AppleScript. On a Mac, this can easily be done on the command line with the built-in textutil utility.

textutil -convert txt -encoding UTF-8 /Users/martin/Desktop/test.rtf -output /Users/martin/Desktop/test.txt

This conversion process can also be automated with AppleScript using the «do shell script» command. Of course, if you want to read a file with AppleScript (or any other programming language), then you need to know the text encoding of the file (e.g. UTF-8, Mac OS Roman, Windows Latin 1) to avoid problems. The textutil command shown above uses UTF-8 for the text encoding, therefor you can read the file in AppleScript as follows:


read (POSIX file "/Users/martin/Desktop/test.txt") as «class utf8»

Text encodings can be tricky, so watch your step (e.g. BOM vs. No-BOM {byte order mark}) :wink:

I guess that is due to some setting in the theme itself. As I said before, Keynote is scriptable, but (in my opinion) it’s not a joy to do so. Just look at PowerPoint’s AppleScript Reference :smiley: It’s huge!

I am trying to do something similar, but not quite sure how to do it.

I am trying to generate open captioning, or subtitles, from the speaker notes. The intent would be that anyone could write the notes, then text-to-speech could read the text… however, the subtitles need to be entered into iDVD or other software (I think).

Is is possible to insert a text field over the current slide, based on short piece of the notes (e.g., hard enter in the notes), to have an opaque box appear across the bottom 1/3 of the screen and then text automatically insert based on the timing of what was actually being read by text-to-speech?

Note example:
Hello, today I will be talking
with you about Community
Health Assessments. This
presentation was originally
delivered at…

This would allow anyone to write their notes and be able to package a presentation without having to speak the text or have someone script in the open captions.

Any thoughts would be helpful. - Thanks.