Press "ok" after few second in Dictation with Applescript

Hi !

I try to write text with dictation in textedit with applescript.
I managed to create a script that runs dictation, but I can’t stop him to do his job as dictation transcription.
I have trying to say click “ok”, but it doesn’t work.

this is my code :

repeat

      tell application "TextEdit"

activate
end tell

      tell application "System Events" to click (menu item "Démarrer Dictée" of menu) of ¬
                (menu bar item "édition" of menu bar) of (application process "TextEdit")

delay 5

      tell application "System Events"
                keystroke "return"
      end tell

delay 5

print without print dialog

delay 5

      tell application "TextEdit" to delete (every paragraph of document 1)

end repeat
return

Thank you very much for your help !!

The line ‘keystroke “return”’ is telling AS to type out the word return, not to hit the return key. Try experimenting with these:

key code 36

--OR

try
	tell application "System Events" to tell process "textEdit" to click button 1 of front window
end try

Also, as written, your script is an infinite loop. Unless you write a way for the script to know when to end, only an unexpected error or you manually stopping/force quitting the script will end it.