How to randomize Keynote slides

user1375267 picture user1375267 · May 4, 2012 · Viewed 8.8k times · Source

I'm a teacher and would like to use Keynote slides as flashcards for spelling. I cannot script and am looking for something to be copy/pasted into Applescript Editor and run from there. I came across the following script in another thread and it is close to what I need.

tell application "Keynote"
    tell slideshow 1
        show slide 3
        show slide 2
        show slide 1
        show slide 4
    end tell
end tell

However, there are two problems for my purposes: 1. It is not a random order and would be tedious to write out for several different presentations of different lengths. 2. There is no control for the length of time each card is shown.

Any advice would be greatly appreciated.

Answer

jackjr300 picture jackjr300 · May 4, 2012

Here is a script that mixes the indexes and wait between each slide

set tdelay to 5 -- seconds  -- the length of  time each card is shown.

tell application "Keynote"
    activate
    tell slideshow 1 to repeat with i in my mixIndexes(count slides)
        show slide i
        delay tdelay
    end repeat
end tell

on mixIndexes(n)
    set l to {1}
    if n is 1 then return l
    repeat with i from 2 to n
        set end of l to i
        set j to some item of l
        tell item i of l to set {item i of l, item j of l} to {item j of l, it}
    end repeat
    return l
end mixIndexes