Using consistent key mappings across OS X applications

This morning, I was delighted to see an update for Textmate - but as I scanned the release notes, I was temporarily irked to learn the key combinations for tabbing between files had been changed.  "Tabs" are a major user interface element that makes web browsing and code editing into a more effective experience, but it's really annoying when different programs use different keys to do the same thing.  In this case, Google Chrome, Terminal.app, and TextMate have all used slightly different mappings at different times, and life would be so much easier if they were all the same.  Fortunately, OS X makes it very easy to control keystroke combinations, so I quickly changed Textmate to use my familiar tab forward/backward configuration - and I'll show you how to do this yourself.

Keyboard Shortcuts to the rescue

OS X provides an interface for mapping any key combination onto any menu item.  In terms of an application like TextMate, when you see a pull-down menu option like "Next File Tab", you can change the keys for that item to any combination you want.

Textmate, Next Tab

Start by opening the Keyboard control in System Preferences

System Preferences, Keyboard

Then click on the Keyboard Shortcuts tab at the top of the window, then select Application Shortcuts in the left column.

Keyboard Shortcuts, Application Shortcuts

Next, click on the + icon, which will enable you to create a new mapping.

Application, Menu Title

In the screenshot above, it says "tell TextMate to call the Next File Tab option whenever I press a certain keyboard combination."  You can add any application you want by pulling down Application, then finding "other" at the very end of the list:

Other Application"

And that does the trick!  TextMate behaves exactly like I want, even though they changed the key mappings with the latest release.  This principle generalizes to almost any OS X application out there, with certain notable exceptions like X11 programs.

What makes a good key combination?

This is a rather philosophical question, but one framework approaching it is this: the most common commands should be the easiest to type.  This property can be measured in terms of whether you can do the keystroke one-handed (e.g. cmd-s) versus two-handed (cmd-^), or in terms of how far you have to stretch your fingers to reach the keys (cmd-z versus cmd-y).  I am using cmd-alt-arrow keys to control my tabs, which is a two-handed combination.  I might even consider switching to something simpler, but I'm used to this combination by now, and I use the same combination in several different applications...  so it's probably here to stay.

Now that you know how to control any application, you can normalize between applications too.  This process is so simple, and it can relieve so many little headaches.  Enjoy!

Read and Post Comments

handy utility: watchpaths

Imagine you are working on a set of files on your computer, and each time you change one of those files, you want to run a program to process the files again. This comes up all over the place, whether it's software development, statistics, image processing, or lots of other domains. Recently, I was editing some source code, and each time I changed a file, I wanted to run a series of tests to make sure everything still worked. I made this process automatic with the help of a really handy utility called watchpaths.

Installing watchpaths

First, download watchpaths and place it somewhere in your path. I use ~/bin, so try something like this:

cd ~/bin
wget https://github.com/iandennismiller/watchpaths/raw/master/bin/watchpaths.py
chmod 755 ~/bin/watchpaths.py

Using watchpaths

Let's say I want to monitor a folder containing images, and each time a new image is added I want to sync the folder to a remote computer. Using watchpaths, that will look like:

watchpaths.py "rsync -a ~/my_pictures user@example.com:public_html" ~/my_pictures

To convert that command into English, it would sound like this:

"Watch the my_pictures folder for any changes (new files, deleted files, updated files, etc) and each time a change happens in that folder, synchronize the contents of that folder with my web server."

More Information

The project page, including links for downloads, is here. If there is any interest, I am happy to incorporate feedback.

Read and Post Comments

Passwords, and the Apple Keychain

Some time around 2006, I started thinking about my online passwords in a new way. Until this point, I had used a collection of perhaps a dozen gibberish passwords, which I reused on various sites depending on the sensitivity of the site. For example, my bank account would use a nearly unique password, whereas a random forum would use a very commonly reused password.

This worked acceptably well, but I frequently had to ask myself: "which password did I use when I signed up for this service?" In response to having to guess my own passwords, I made two decisions: I would start writing my passwords down, and I would make them all unique and randomly generated. Four years later, I am using a totally different system, and I'll explain all of my reasoning.

To facilitate my random password approach, I started using 3x5 index cards and a card filer. I added A-Z tabs, and I generally filed cards according to the domain name of the service (e.g. paypal.com is filed under P). I wrote a quick perl script to make 10 random passwords at a time, and I would pick one from the list and write it down on the index card. I really liked the concept of a purely non-digital password storage system, because it would be essentially unhackable without physical access. Essentially unhackable - more on this later.

There were several drawbacks to the index card system. For brevity, I'll just list them:

  • writing some characters by hand is ambiguous. I confused capital I, lowercase L, and numeral 1 all the time. Capital O and numeral 0 are also a trick.

  • it's possible to copy the password incorrectly

  • it is extremely difficult to create a backup copy, so catastrophic loss is a possibility

  • if someone has physical access to the index cards, they have access to your accounts

  • it's tedious to type in a random password every time you log in

  • it doesn't scale well after about 400 accounts

The scaling problems were the real killer. For example, did I file sandbox.paypal.com under P for paypal or S for sandbox? I don't remember, so I need to perform a linear search through both letters. Or, since a disproportionate number of words start with S, then it became a more tedious task to flip through all the S cards in order to find an S site, whereas a site that started with Y would be pretty quick to look up since there were fewer. Eventually, it got to the point that I knew it was too much of a chore to look up cards, and on that basis, I became too lazy to log in to my accounts! Total failure.

keychain icon

The solution for me is to use Apple Keychain. If you're a GTD adherent, then you'll understand what I mean when I say this is my trusted system for account information. How did I reconcile a digital password storage with my original goal of keeping my passwords offline in order to make it unhackable? It was when I realized that both offline passwords and the keychain can be successfully attacked with a keystroke logger. If someone went to those lengths to get a password, then it wouldn't matter how it was originally stored; the password could be intercepted regardless.

Why use Apple Keychain? Based on my list of drawbacks for the index cards, here's a list of pro-Keychain points:

  • built-in random password generator

  • keyword search

  • simple cut-and-paste workflow makes it very easy to enter passwords without typing

  • keychain itself is password protected

  • passwords are Triple DES encrypted (which should be acceptable until the year 2030)

  • simple to back up keychain file

  • slick integration with many applications, including Mail.app, subversion, and Safari/Chrome.

I'm currently at about 900 accounts (yes - this is deserving of a separate post unto itself) and the system is working great. I think this scales to meet my requirements, and probably beyond. In practical terms, a password that used to take 30 second to retrieve is now instant. I probably save 5 minutes per day by switching away from index cards, and I am avoiding untold frustrations. In all, I recommend Apple Keychain highly.

Read and Post Comments