kotfu.net

A Command Line Tool For MacOS Shortcuts

If you write about anything on the Mac, you will probably have to write about keyboard shortcuts. Apple’s Style Guide has very detailed instructions for how to reference and document keyboard shortcuts. I can never remember all the rules, so when I write about keyboard shortcuts, they are far from consistent.

Brett Terpstra wrote created a Jekyll plugin called kbd for documenting Mac keyboard shortcuts. His plugin implements Apple’s rules, and if you are writing in Jekyll, it’s great.

However, I write about shortcuts in many more places than Jekyll, and his work inspired me to create a command line tool called ksc to do the same thing. Here’s how it works:

$ ksc command shift %
Shift-Command-5
$ ksc ctrl esc
Control-Escape
$ ksc shft-cmd-t
Shift-Command-T

Notice how it’s all nicely formatted, with the modifier keys in the proper order, and shifted keys described per Apple’s guidelines. See the README for more details, including lots of command line options to control how the output is rendered.

You’ll need Python 3 to use this script, and I’ll be adding Keyboard Maestro, Alfred, and TextExpander macros soon so that you can use this tool anywhere you can type on your Mac.