Pretending to type like a Hollywood hacker in Sublime Text 2

Christian Heilmann has just drawn my attention to a neat trick for automating typing into a text editor, from William Bamberg at Mozilla. Basically, when you’re doing a screencast, popping up a screen full of code is disorienting and hard for your users to take in, but if you actually type the stuff live on air then everyone gets to see all your typos and your mic makes it sound like a herd of wildebeest sweeping majestically across your keyboard.

Bamberg’s solution is to have an AppleScript which reads the file of your choice and then sends keypresses to your editor to “type” the file in, and it’s a neat idea. However, that’s Mac-specific so I can’t use it, and it doesn’t (as Chris notes) work in Sublime Text 2 (my editor, and his) because ST2 does autoindenting and so on and that sods you up.

Conveniently, I needed a script to do precisely this for some screencasts I’m about to work on, so I thought: I shall write it as an ST2 plugin. And lo, I have done so. It’s only about 30 lines: in ST2, do Tools > New Plugin, then paste the Python from https://gist.github.com/stuartlangridge/8336771 and save it as TypeFileOut.py in the ST2 User folder (which should be default).

You then need a way of running it: I added a keybinding for it in Preferences > Key Bindings -- User so that file now looks like

[
    { "keys": ["ctrl+shift+."], "command": "type_file_out" }
]

so I can press ctrl-shift-fullstop.

What it actually does is: when you run it, it removes all the text in the current editing tab, waits two seconds, and then types it back in, character by character. The two second wait is to give you a cut point for the screencast, so you enter or load the code you want into ST2, then start your screencast showing slides or whatever, switch to ST2, then press ctrl-shift-. and it’ll type the text back in. When you’re editing your screencast, cut the part between switching to ST2 and the 2 second break.

http://www.youtube.com/watch?v=vO5y3CtEGtc

There’s probably a way of packaging this up so other people can download it with a click, but I don’t think I know how to do that.

More in the discussion (powered by webmentions)

  • A response was written at Pretending... (www.kryogenix.org) Christian Heilmann has just drawn my attention to a neat trick for automating typing into a text editor, from William Bamberg at Mozilla. Basically, w…
  • A response was written at Pretending... (www.kryogenix.org) Christian Heilmann has just drawn my attention to a neat trick for automating typing into a text editor, from William Bamberg at Mozilla. Basically, w…