Skip to content

Instantly share code, notes, and snippets.

@goldengrape
Last active September 11, 2021 14:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save goldengrape/eb4359a6467c5196435e469708c95f11 to your computer and use it in GitHub Desktop.
Save goldengrape/eb4359a6467c5196435e469708c95f11 to your computer and use it in GitHub Desktop.
Simple Play and Say.scpt
property defaultSlideDuraton : 2
property pauseBeforeSpeaking : 0 -- 1.5
property stoppingStatement : "[[slnc 1000]] Stopping presentation."
-- my startRecordScreen
tell application "QuickTime Player"
activate
set newScreenRecording to new screen recording
tell newScreenRecording
start
end tell
end tell
tell application "Keynote"
activate
try
if not (exists document 1) then error number -128
if playing is true then stop the front document
tell document 1
set the slideCount to the count of (slides whose skipped is false)
start from (first slide whose slide number is 1)
end tell
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert (("ERROR " & errorNumber) as string) message errorMessage
end if
end try
end tell
tell application "Keynote"
try
repeat with i from 1 to the slideCount
log i
if playing is false then
my speakSlideNotes(stoppingStatement)
error number -128
end if
tell document 1
repeat
set currentSlideNumber to (get slide number of current slide)
if currentSlideNumber is equal to i then exit repeat
my idleForThisTime(1)
if my playingStatus() is false then
my speakSlideNotes(stoppingStatement)
error number -128
end if
end repeat
set thisSlidesPresenterNotes to presenter notes of current slide
end tell
if thisSlidesPresenterNotes is "" then
delay defaultSlideDuraton
else
if pauseBeforeSpeaking is not 0 then
delay pauseBeforeSpeaking
end if
my speakSlideNotes(thisSlidesPresenterNotes)
end if
if i is slideCount then
exit repeat
else
if playing is false then
my speakSlideNotes(stoppingStatement)
error number -128
end if
repeat 10 times
tell document 1
set cNum to (get slide number of current slide)
end tell
if cNum is not equal to i then
exit repeat
else
show next
say "," -- I really don't know why I have to say something here, english comma is a sound of silence
end if
end repeat
end if
end repeat
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert (("ERROR " & errorNumber) as string) message errorMessage
end if
end try
end tell
-- my stopRecordScreen
tell application "QuickTime Player"
try
tell newScreenRecording
stop
end tell
end try
end tell
tell application "Keynote"
try
tell document 1 to stop
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert (("ERROR " & errorNumber) as string) message errorMessage
end if
end try
end tell
on speakSlideNotes(thisSlidesPresenterNotes)
say thisSlidesPresenterNotes with waiting until completion
end speakSlideNotes
on idleForThisTime(idleTimeInSeconds)
do shell script "sleep " & (idleTimeInSeconds as string)
end idleForThisTime
on playingStatus()
tell application "Keynote"
return (get playing)
end tell
end playingStatus
@goldengrape
Copy link
Author

known issue:
If there is an animation, the "show next" would play the animation, but not show the next slides. you have to click manually.
setting animation to autoplay in keynote could solve the problem partially

@goldengrape
Copy link
Author

the magic code:

repeat 10 times
    tell document 1
		set cNum to (get slide number of current slide)
    end tell
    if cNum is not equal to i then
		exit repeat
    else
		show next
		say "," -- I really don't know why I have to say something here, english comma is a sound of silence
    end if
end repeat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment