Creating REAL typewriting effect on mac (similar to Type.js but with actual keyboard input)

When recording a programming demonstration video, I want to automate the typing according to a manuscript. Basically w looking for a tool/technique that will enable me to script lines/files/strings and make that act as it coming from my actual keyboard (at configurable speed). I will then screen record my IDE, command line or whatever application and trigger the script to capture a sequence of faked typing. All of this to make it look at least semi-human.

For JavaScript there is several tools, for instance Typed.js. I am looking for a Mac equivalent. Does this exist?


Solution 1:

Here as quick and dirty answer with some Apple script I found online:

set fc to read POSIX file "/path/to/file.txt" as «class utf8»

set the text item delimiters to (ASCII character 10)
set mylines to text items in fc
repeat with currentline in mylines
    write_string(currentline)
end repeat

on write_string(the_string)
    tell application "System Events"
        tell application "TextEdit" to activate
        repeat with the_character in the_string
            keystroke the_character
            delay 0.05
        end repeat
        key code 36
        key code 123 using command down
    end tell
end write_string

The Apple script requires an empty open document in TextEdit and a source text file /path/to/file.txt (with strings/text etc.).

It probably works with other text editors also.

Additional keystroke sound and random delays:

If you replace

            keystroke the_character
            delay 0.05

with

            do shell script ("afplay " & "/path/to/sound.wav" & " > /dev/null 2>&1 &")
            keystroke the_character
            set d to random number from 0.2 to 0.5
            delay d

you will get some sound too. (example keystroke sound file (direct d/l link!))

Additional office sound:

Add the line somewhere at the beginning of the script. You can set the volume with "-v "!

do shell script ("afplay " & "/path/to/officesound.wav" & " > /dev/null 2>&1 &")

Example: office sound - People - indoor crowd - government office - people in queue. (requires Login/Register)


If I find some time, I'll add some open new document ... lines.