hacking # on mac keyboards

oliver on 2006-12-31T13:03:45

A very nice new toy recently landed on my desk at work, an Apple MacBook. It's my first Mac and I'm very impressed so far. One of the things I want to use it for is hacking Perl whilst on the move.

To get a # sign on the MacBook keyboard you use the Option (or Alt) key + 3. This seems terribly klunky to me, and # is of course used quite a bit in Perl. The other problem is that you might have the Alt key mapped to something else in a Terminal application.

This hack remaps another key on the keyboard to produce the # character. I chose the funny squiggle that's to the left of the number 1 key (§). This is the Section sign, used in document formatting. Just create a file at ~/Library/KeyBindings/DefaultKeyBinding.dict that contains the following:

{
    /* this will make all § turn into # */
    "\UA7" = ("insertText:", "#");
}

Any app that uses Apple's Cocoa interface widgets for text input will pick this up after being restarted. There are some that don't (perhaps TextMate? Not checked that one so if you know, please comment).

A lot more information about this is available at this excellent page on the Cocoa Text System, including some other neat hacks. Enjoy!


US Layout

Dom2 on 2006-12-31T17:20:58

I just switched my keyboard to a US layout. It's far easier than trying to use Apple's british layout. Mostly because as well as the hash issue, the british layout also screws up double quote and apostrophe signs. Bleargh.

-Dom