Terminal Keyboard Macro

Find yourself typing the same thing repeatedly in the Terminal app on OS X?  Wish you could keyboard macro something that works regardless of what shell, sub-shell, or program you’re in?  Well you can.

I’ve been doing a bit of Erlang programming lately and got tired of having to change working directories so that I could compile my .erl files into .beam files and have them appear in the right place.

A bit of research led me to Learn You Some Erlang and a nice chapter on modules.  There it covered how you don’t always have to do this:


You can, in fact, tell the compiler to save the .beam in any arbitrary location.  While that page didn’t explain how, this one did.  (Yes, the command is ‘file’ not ‘compile’, but Erlang is a bit weird like that.)

Anyhow, you can get that down to a single line:

c("/path/to/the/module/myModule", [ {outdir,"/path/to/your/ebin/directory/"} ] ).

You can then bind that whole command to a single keystroke in Terminal.

Terminal > Preferences... > Settings > Keyboard

Just select a convenient key (or keystroke combination) from the list, double-click to edit it, and replace the contents of the bottom field with whatever macro text you want.  (Note that control characters (like enter, delete) can also be encoded into the macro.)

Easy as that.  Simple macros for whatever Terminal commands you find yourself doing a lot, and no need to install special software.

PS:  In my case I used F14 and full paths ("/Users/tim/Dropbox/project/...") so that the command would work regardless of where I was and what the current working directory was.  One-key compilation and no need to change directories – yeah baby!


3 thoughts on “Terminal Keyboard Macro

  1. Interesting stuff. I’ve taught myself dozens of computer languages over the years. Erlang looks sufficiently interesting (and weird) that I’ve downloaded and installed it on my computer tonight. (A bit of a silly thing to do as I shouldn’t be distracting myself before the end of the year… but I kinda can’t help being in a semi-permanent state of distraction — makes me virtually unemployable.)

    Thanks for introducing me to what may turn out to be a useful language.

  2. I believe that the elegance and efficacy of a program has less to do with the language it was written in and more to do with how naturally the programmer ‘thinks’ in that language. (I can write in Perl as easily as I can write in English, for example.) The only obstacle, then, to becoming an efficient programmer is having the tenacity to keep on trying new languages until you find one that ‘clicks’ for you. I hope the distraction moves you one step closer to finding that language.

  3. Very well put. This is one of my main arguments against strongly typed languages like Java, Pascal, Ada, and similar: they force a human to think unnaturally, like a computer. Languages like javascript, perl, and so on, are much closer to how humans think and therefore much more productive. (I almost include python there, but I get the impression they’re intent on making it harder to use in recent versions.)

    Of course there are some fun languages like FORTH and sed that are weirdly alien to how humans think, but have other great advantages in size and conciseness. And there are some assembly languages (6809 is my favorite) that are almost like higher level languages.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s