AppleScripting Keynote 3
Tue Jan 30, 2007 · 229 words

And in particular the add chart command. At first it seems like a really cool thing - easily create beautiful charts out of virtually any source. I was excited to try this with some Webalizer output. Looks like you have two options - the Automator Action or Script Editor

The action produces a chart right off the bat, but the input is weird:

Input: (Anything) Two dimensional array of chart labels and data.

What is that? After trying every possible permutation of what I thought an AS 2D array would look like (some of which even compiled!) with different kinds of input sources (AS, text) I finally gave up on the Automator Action option.

Using script editor seemed promising at first, but a simple add chart with all the properties produced nothing. Finally managed to find this really nice example, but it only worked with Pages. Digging in the action's bundle revealed that you're supposed to tell the slide to add the chart. OK, time to put this new-found knowledge to work:

tell application "Keynote"
    set theData to {{1, 2, 3}, {4, 5, 6}}
    set theSlide to (slide 1) of first slideshow
    tell theSlide
        add chart row names {"Dec", "Jan"} column names {"Machines", "Visits", "Hits"} 
        data theData type "vertical_bar_3d" group by "column"
    end tell
end tell

Pasted Graphic 2

Tadaa! Sweet. Now all that remains is to add the webalizer parsing code…


back · essays · credits ·