Populating a Keynote Presentation From a Numbers Spreadsheet Using JavaScript

You can use the Script Editor app on your Mac to create JavaScript programs that control other apps. In this example, learn how to take data from a Numbers spreadsheet and use it to add new slides to a Keynote presentation. While it takes some programming know-how to build automation tasks like this, it is good to know what is possible.

Here’s the text of the script:

var Numbers = Application("Numbers");
var Keynote = Application("Keynote");

var table = Numbers.documents[0].sheets[0].tables[0];
var presentation = Keynote.documents[0];
var slideMaster = presentation.masterSlides["Title & Subtitle"];

for(var i=1;i<table.rowCount();i++) {
    var newSlide = Keynote.Slide({baseSlide:slideMaster});
    presentation.slides.push(newSlide);
    newSlide.defaultTitleItem().objectText = table.rows[i].cells[0].value();
	
    var newSlide = Keynote.Slide({baseSlide:slideMaster});
    presentation.slides.push(newSlide);
    newSlide.defaultTitleItem().objectText = table.rows[i].cells[0].value();
    newSlide.defaultBodyItem().objectText = table.rows[i].cells[1].value();
}

Comments: 8 Responses to “Populating a Keynote Presentation From a Numbers Spreadsheet Using JavaScript”

    nick
    8 years ago

    very slick Gary, looking forward to more programming examples, great way to learn Java !

    Leah
    8 years ago

    This is super. I'm also very interested in writing little scripts for the Mac. Thanks!
    (Club MacMost patron ;)

    Eric
    8 years ago

    Nice one. Could you please make the script available as a starting point for experimentation?

    8 years ago

    Eric: I'm put the script under the video above for those that wish to copy and paste.

    John Luke
    8 years ago

    This script was a great help! Do you know how to add another text box and fill it the same way as defaultTitleText and defaultBodyText??
    Additionally, do you know how I could use a lookup script to update these text boxes? (example would be updating prices in a product portfolio).
    Thanks again!

    8 years ago

    John: Looks like we only have those two existing text boxes to work with in scripts. The other idea may be possible, but I can't think of how to do it offhand. You'd need to start experimenting and work at it to figure to out.

    Dorit
    8 years ago

    Trying to get from the "fish"to the "fishing": Is there some documentation (presumably by Apple) to find out about those pre-defined capabilities of Numbers and Keynote? I. e. how do I find out that it's "presentation.masterslide" or "newSlide.defaultTitleItem().objectText()"?

    8 years ago

    Dorit: There is documentation in the Script Editor app. Use Window, Library to open the topic list. Then dig into a topic. But remember to switch from AppleScript to JavaScript at the top of the documentation window. The information here is just a reference and is sorely locking in examples.

Comments Closed.