AppleScript How To "keystroke" Slower

I am currently making a "Choose your own adventure" game using AppleScript. I need it to type out text just a bit slower then usual using "keystroke". I have typed out each letter of each word and added delays manually, but I don't want to type them out letter by letter going forward. Would there be a way to cut each sentence letter by letter, then type them out slowly, maybe with "to"? (AppleScript and "to" example below)



"To" Example


to typeTextSlowly(textToType)
//Need some help here

//Would be called with the code below

//Some random code
typeTextSlowly("text")
//Some random code




Manually Made Code


tell application "System Events"
	keystroke "H"
	delay 0.03
	keystroke "e"
	delay 0.03
	keystroke "l"
	delay 0.03
	keystroke "l"
	delay 0.03
	keystroke "o"
	delay 0.03
	keystroke "."
	delay 0.5
	keystroke " "
	delay 0.03
	keystroke "N"
	delay 0.03
	keystroke "i"
	delay 0.03
	keystroke "c"
	delay 0.03
	keystroke "e"
	delay 0.03
	keystroke " "
	delay 0.03
	keystroke "t"
	delay 0.03
	keystroke "o"
	delay 0.03
	keystroke " "
	delay 0.03
	keystroke "s"
	delay 0.03
	keystroke "e"
	delay 0.03
	keystroke "e"
	delay 0.03
	keystroke " "
	delay 0.03
	keystroke "y"
	delay 0.03
	keystroke "o"
	delay 0.03
	keystroke "u"
	delay 0.03
	keystroke "!"
end tell



Posted on Dec 11, 2020 6:38 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 11, 2020 7:09 AM

Use code such as:


set theString to "text"

tell application "System Events"

repeat with thisChar in theString

keystroke thisChar

delay 0.03

if thisChar is "." then delay 0.47

end repeat

end tell


(187938)

Similar questions

2 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript How To "keystroke" Slower

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.