applescriptkeynote

How could I use applescript to play keynote slids?


everyone

I try to use applescript to play my keynote slid,but occure error

set thisFile to "/Users/usrname/Desktop/cardtest.key"
tell application "Keynote"
    activate
    open thisFile
    start thisFile from the first slide of thisFile
end tell

this code will open keynote file successfully,but can't run slids.

the error was keynote error : can't make "path" become type "document".

I tried to use:

tell slideshow 1

but another error: slideshow should be the end of sentence, should not have 1.

have no idea why.


Solution

  • You are going to start a POSIX path rather than a Keynote document.

    This is exactly what the error is telling you.

    You have to use the reference to the opened document

    set thisFile to "/Users/usrname/Desktop/cardtest.key"
    tell application "Keynote"
        activate
        set currentDocument to open thisFile
        tell currentDocument to start from first slide
    end tell