Create Keynote '09 slide from Numbers '09 selection

Jan 09, '09 07:30:02AM

Contributed by: robg

One of the new things in Numbers '09 is AppleScript support. As an example of what's possible -- and the kind of code you'll need to use to get the current sheet and selected cells -- AppleScript guru Sal Soghoian sent in the following example. This code takes the selected cells in a Numbers table and converts them into a bulleted slide in Keynote with the selected values.

try
  tell application "Numbers"
    tell document 1
      -- DETERMINE THE CURRENT SHEET
      set current_sheet_index to 0
      repeat with i from 1 to the count of sheets
        tell sheet i
          set x to the count of (tables whose selection range is not missing value)
        end tell
        if x is not 0 then
          set the current_sheet_index to i
          exit repeat
        end if
      end repeat
      if the current_sheet_index is 0 then error "No sheet has a selected table."
      -- GET THE VALUES OF THE SELECTED CELLS
      tell sheet current_sheet_index
        set the current_table to the first table whose selection range is not missing value
        tell the current_table
          set the range_values to the value of every cell of the selection range
        end tell
      end tell
    end tell
  end tell
  -- CONVERT THE VALUES LIST TO PARAGRAPHS
  set AppleScript's text item delimiters to return
  set the bullet_points to the range_values as string
  set AppleScript's text item delimiters to ""
  -- CREATE A NEW SLIDE AND USE THE VALUES LIST AS BULLETS
  tell application "Keynote"
    activate
    tell slideshow 1
      set this_slide to make new slide at the beginning of slides
      tell slide 1
        set body to the bullet_points
      end tell
    end tell
  end tell
on error error_message
  display dialog error_message
end try
To use this, save it out of Script Editor as a script to your user's Library » Scripts » Applications » Numbers folder -- you may have to create some of the folders at/below the Scripts folder. Then within Numbers, select the range you wish to move to Keynote, and then use the Scripts menu to select and run your new script.

While this worked, it dumped the body into the subtitle section of the default new slide in Keynote. Looking at the AppleScript dictionary for Keynote '09, it appears it should be possible to create a new slide with a given master, so that the pasted data would wind up in an actual bullet body section -- but I'll leave that as an exercise for the experts!

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090109055630154