shortcut magic – run rspec tests with a keyboard shortcut.

I’m still tweaking my screen layout in vscode a lot. One thing I really don’t like is that the terminal has to be fixed to the bottom. That means I can’t get much height out of it unless my code window is tiny. I played with turning my monitor, but that felt pretty bad for my neck and didn’t make me feel better about my layout. Last week I stopped using the vscode terminal and started using iTerm again. That was better, but now I needed to use my mouse or a bunch more shortcuts in order to switch to iTerm, press up to get the previous command, and then switch back to the code to start fixing. Then today I had a good idea!

Idea: use a system-wide keyboard shortcut to re-run the last command in the terminal.

It’s really simple: I set up an automator task that switches to iTerm, presses the up arrow, and then presses enter. I set the shortcut to be command f3, so now I can run my tests without taking my hands off the keyboard (and in one shortcut!) I also had to make sure vscode wasn’t using that shortcut. This is written in a funny little scripting language called applescript. It’s been baked into osx for forever and it’s fairly readable.

Applescript code block in automator
System prefs showing how to set a keyboard shortcut for an action

Now while I’m doing red-green-refactor I’m able to save time with fewer clicks. It’s a tiny example of ‘automating toil’, but it makes me smile whenever I save a second.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.