Skip to content

Instantly share code, notes, and snippets.

@PradyumnaKrishna
Last active January 9, 2021 15:03
Show Gist options
  • Save PradyumnaKrishna/a3f38fc84b2546bdf322857af1d1942a to your computer and use it in GitHub Desktop.
Save PradyumnaKrishna/a3f38fc84b2546bdf322857af1d1942a to your computer and use it in GitHub Desktop.
TypeWriter Effect to Write with AppleScript
# path to file for to read
set fc to read POSIX file "/Users/phoenix/Github/devops/app.py" as «class utf8»
global chars1
set prev_char to "a"
set chars1 to {" ", "\"", "(", ",", "\\", "=", "_", "@", ")", ".", ":"}
set the text item delimiters to (ASCII character 10)
set mylines to text items in fc
repeat with currentline in mylines
delay 1
write_string(currentline, prev_char)
end repeat
on write_string(the_string, prev_char)
tell application "System Events"
# Choose runing application (Currently TextEdit)
tell application "iTerm" to activate
repeat with the_character in the_string
# path you keystroke file for sound
do shell script ("afplay " & "~/Desktop/keystroke.wav" & " > /dev/null 2>&1 &")
if the_character contains prev_char then
set d to 0.07
else if chars1 contains the_character then
set d to random number from 0.27 to 0.32
else
set d to random number from 0.06 to 0.18
end if
delay d
keystroke the_character
set prev_char to the_character
end repeat
delay 0.1
do shell script ("afplay " & "~/Desktop/keystroke1.wav" & " > /dev/null 2>&1 &")
key code 36
key code 123 using command down
end tell
end write_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment