Convert Numbers sheets into Keynote slides via AppleScript

Feb 12, '10 07:30:00AM

Contributed by: Anonymous

I wrote an AppleScript to copy all the tables and data from a Numbers document into a Keynote document. Each sheet becomes on slide on Keynote. Here's the code:

tell application "Keynote"
  activate
  make new slideshow -- create a slide show
  set newSlideShow to slideshow 1 -- keep a reference
end tell

tell application "Numbers"
  activate
  tell document 1
    set nombreFeuilles to the count of sheets
  end tell
end tell
--display dialog nombreFeuilles

repeat with i from 1 to nombreFeuilles
  tell application "Numbers"
    activate
    tell table 1 of sheet i of document 1 to activate
    
    tell application "System Events" to keystroke "a" using {command down}
    tell application "System Events" to keystroke "c" using {command down}
  end tell
  
  tell application "Keynote"
    activate
    set newSlide to make new slide at the end of newSlideShow
    tell newSlide
      tell application "System Events" to keystroke "v" using {command down}
    end tell
  end tell
end repeat
I did not find many examples of AppleScript for iWork, so I thought I could share this one.

[robg adds: We have one additional hint about Keynote, Numbers, and AppleScript; in that hint, a selection in Keynote is transformed into a slide in Keynote via AppleScript.]

Comments (0)


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