-
-
Save fujohnwang/aff0b7f3242be27da2ee19fa359efcd7 to your computer and use it in GitHub Desktop.
Simple Play and Say.scpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment