Force Keynote in presentation mode and quit after last slide

I need to open Keynote files programmatically via Node.js. using

open -a Keynote -W "path/to/file.key"

everything works well. But there are two tasks I cannot solve:

  1. the presentation needs to start directly so no further user interaction is necessary.

As I have no control over the presentation itself, I cannot alter the files to start in presentation mode. Somehow I have to tell Keynote. In Powerpoint this is possible via the /s Argument (powerpoint.exe /s "path/to/presentation.pptx" will go directly in presentation mode). Does something similar exist for Keynote?

  1. After the last slide I need to quit Keynote

Is there any possibility to tell Keynote to quit after the last slide? My Application needs to know when the presentation is finished and I can track when the program closes, but as default it only closes the presentation, not Keynote itself.


You could use an AppleScript to do this and run it with osascript...

osascript << EOF
if running of application "Keynote" is true then
    tell application "Keynote"
        activate
        try
            if playing is false then start the front document
        end try
    end tell
end if
EOF