Mapping A Hash Keyboard Button In OSX

This article was originally posted in February 2012. Be warned, there may now be easier ways to do this.

When I switched to using a Mac, one of the very few problems I had was the lack of a hash key on my (UK) keyboard. For the average user, this probably isn't too much of an issue but for someone who codes, I can't live without it! Alt + 3 is slightly too awkward a shape to pull off frequently with one hand.

To remedy my problem, i needed to find a donor key on my keyboard. The § key looked like the perfect candidate (I even had to google it to find out what it was!).

The section sign (§, Unicode U+00A7, HTML entity §), also called the "double S", "sectional symbol" or signum sectionis, is a typographical character used mainly to refer to a particular section of a document, such as a legal code.

Well now you know too.

Now for the magic. If you don't already have it, you will need to create a DefaultKeyBinding.dict file here:

~/Library/KeyBindings/DefaultKeyBinding.dict

Once you have this file, open it and add:

/* Map # to § key*/
"§" = ("insertText:", "#");

Save that, restart your Mac and you will be the proud owner of a new hash key!