Skip to content

Instantly share code, notes, and snippets.

@jaymcgavren
Last active April 29, 2019 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymcgavren/dd6c0d34ed5c6786d98e6ef4615fba10 to your computer and use it in GitHub Desktop.
Save jaymcgavren/dd6c0d34ed5c6786d98e6ef4615fba10 to your computer and use it in GitHub Desktop.
Simulate typing out the clipboard contents! Save the below script as an AppleScript or a service in Automator.
set mytext to (the clipboard as text)
write_string(mytext)
on write_string(the_string)
tell application "System Events"
launch
repeat with the_character in the_string
keystroke the_character
delay (random number from 0.05 to 0.25)
end repeat
end tell
end write_string
# based on https://christianheilmann.com/2014/01/09/autmating-typing-in-screencasts-with-applescript-or-how-to-look-like-a-hollywood-hacker/
set my_text to (the clipboard as text)
set the text item delimiters to (ASCII character 13) # CR, not LF!
set my_lines to text items in my_text
repeat with current_line in my_lines
write_string(current_line)
end repeat
on write_string(the_string)
tell application "System Events"
launch
repeat with the_character in the_string
keystroke the_character
delay (random number from 0.01 to 0.12)
end repeat
key code 36 # enter
# Cope with autoindent by deleting to start of line
key code 123 using {shift down, command down} # left arrow
key code 51 # delete
end tell
end write_string
@jaymcgavren
Copy link
Author

Inspired by http://christianheilmann.com/2014/01/09/autmating-typing-in-screencasts-with-applescript-or-how-to-look-like-a-hollywood-hacker/ (which includes a hack to make it work with editors where you can't turn auto-indent off).

@jaymcgavren
Copy link
Author

I now have to work with an editor where I can't turn auto-indent off, so I included the aforementioned hack in simulate_typing_clipboard_cope_with_autoindent.txt.

@jaymcgavren
Copy link
Author

jaymcgavren commented Apr 29, 2019

I'd also like to point out a weird coincidence: it's been a year to the day between comments. ¯\_(ツ)_/¯

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