MacOS X Stuff


Update: uControl 1.0.6 should resolve all kernel panics with Mac OS 10.1.5. There were some reported for the iBook after I released 1.0.4, who I've asked to try this new version which they say works well. The new version also features a new Preference Panel (screenshot), so you can configure the options you want. Also, uControl no longer requires a restart. I finally figured out how to run a few installation scripts.

Warning: the latest OS X update to 10.1.5 (or build 5R60) will break uControl 1.0.3 and 1.0.4 and render your machine unbootable. If you've already updated, you must boot into single user mode (hold CMD-S, while booting). Remount your drive writable (mount -uw /). Then remove the start up file (rm /Library/StartupItems/uControl/uControl). If you haven't updated yet, remove that file before you do. Hopefully, now that I have something to work with I'll be able to fix this shortly.

Download uControl
Mac OS X versiondownload
10.1.5 version 1.0.6 uControl1.0.6.pkg.zip (source uControl1.0.6.tgz)
10.1.4, 10.1.3, 10.1.2, 10.1.1 version 1.0.3 uControl1.0.3.pkg.tgz (source uControl1.0.3.tgz)
10.0.x version 1.0.1 iControl.dmg.gz (source iControl.tgz)

Take Control!

Tired of hitting all the wrong modifier keys on your laptop to get that simple control sequence? Are you forced to drag a keyboard around with you that has the control key in the right place? The place that Apple mistakenly put the caps lock key. Take control back!

uControl maps your control key to it's rightfully intended place on your laptops keyboard; the place thats currently occupied by the oft-unused caps lock key. No more finger acrobatics are required for using control-intensive Unix applications.

Features

This started out as a simple hack with one intent in mind, to remap the caps lock key to control, but due to various requests it's had a number of enhancements.

Known Problems

I know this utility works on TiBooks, but unfortunately that's the only machine I have to test it on. I hope some gracious soul will be kind enough to lend some time to provide me with a patch for whatever machine they're using if it doesn't work properly.

If you can consistently reproduce any of other cases that will invariably pop up, definitely shoot me an email and it might lead to a better fix. And hey, if this utility just makes your life easier, by all means send me an email. It makes my day.

-shane (at) terraspring.com

uControl software is licensed under the GNU GPL. Making better software for a better society.

Acknowledgements

uControl and was modified from iJect sources by Christian Starkjohann who works for Objective Development maker of other cool stuff. Who wrote an excellent article on how to do the impossible with C++.

The real magic behind making uControl configurable at runtime had to do with the work by Michael Baltaks' on DoubleCommand (another project derived from iJect).

And they said it couldn't be done!

PowerBook Control and Caps Lock keys can't be remapped
Date Written: 1/27/91
Last reviewed: 6/14/93

Is there any way to make the Caps Lock key behave as if it were the Control key on a PowerBook 170? I've tried playing with 'KCHR' resources, but I can't get the Caps Lock key to not be a sticky control key. The PowerBook 170 is great, except for the placement of the Control key.

For a long time the Macintosh ADB keyboards always had a mechanical Caps Lock key, so there's never been any special handling of switching between keycodes while the Caps Lock key is down or up.

With the introduction of the PowerBook keyboards with nonmechanical Caps Lock keys, the Power Manager chip itself is handling this remapping. Thus there is no keyup sequence that is sent from the keyboard, which makes it impossible to write an ADB handler that remaps the keys. Also, there's no way to change the behavior of the keyboard inside or outside the driver, because the keymap handling is hardwired to the Power Manager chip.

So it's not possible to remap the Control and Caps Lock keys with the capability of handling Caps Lock down keycodes. The mapping of keys themselves is trivial, but the handling of different key codes is not.

You can do anything with a computer. You just need to know how to talk to it.

Alternative solution for USB keyboard users: It seems Apple has a little gem for those of you looking to remap your caps lock to control. By simply changing a properties file, you can have your USB keyboard remapped no kernel extension required. Here's an excerpt from John Fieber's page.

Remapping caps lock key to control on a USB keyboard is easier in MacOS 10.1 than in previous versions. The AppleUSBKeyboard driver has a hook built in for swapping the caps lock and control key functions. You just need to add a property to the Info.plist file to activate it. No more recompiling drivers so you do not even need the developer tools. Alas, this is still a global solution...no remapping on a per-user basis which would be ideal.

  1. Edit /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBKeyboard.kext/Contents/Info.plist and add:

    <key>Swap control and capslock</key>
    <integer>1</integer>
    

    under IOKitPersonalities/AppleUSBKeyboard. Here is a properly edited Info.plist for the first release of 10.1, but be aware that other parts of the file may be incorrect for future versions of the driver. You can, of course, use the PropertyListEditor application that comes with the developer tools to add the property.

  2. Remove the file /System/Library/Extensions.mkext. This is a device driver cache. The modified AppleUSBKeyboard driver will not be loaded if this exists. The next reboot will rebuild this file with the modified AppleUSBKeyboard driver. (And the reboot will take a bit longer than normal as it builds the file.)

  3. Reboot.


Twerq!

For you touch typists, be sure to take a look at uControl's cousin Twerq. Twerq does the same thing as uControl (same source actually), but with a little twist. The space bar acts as a shift when held and mirrors the keys. What good is that for? You might ask. Means one hand now has access to all the keys from home row. (Hey what are you doing with that other hand? [shakes head] Keep your mind out of the gutter folks. ;) For anyone with a disability this might be especially useful. For me, it means I don't have to bring back my mouse hand if I don't need to do any extended typing. Supposedly the first keyboard used this kind of corded technique so one hand would be free to use the exotic mouse device. There's a company that sells these sorts of keyboards.



Macs do Emacs? Who knew?

Update: I just received an email that tipped me off to a fantastic piece of software which includes a DefaultKeyBinding.dict file with many more emacs-ish features, but not only that. It includes an InputManager plugin for TextExtras (also requires: MOKit) which gives you good old emacs services like selection piping, programmatic indentation, brace matching, and more in every Cocoa application! It's simply phenomenal, if you like emacs.

When you found out that you had emacs bindings in Cocoa, were you impressed? Then you realized you only got the Control half of the key bindings. Option still just gave you funny characters. Better than nothing, I thought. Well someone behind Mac OS X or NeXT certainly had an affection for definable keybindings and now you can unleash the other half (well most of the other half) by dabbling with a few dictionary files.

I found this gem while looking through the Project Builder release notes, directing me to the Help system to look for "Text System Defaults and Key Bindings" (btw, does anyone else think Apple's new Help is a piece of crap? You can't copy and paste. Navigation is cumbersome at best... nevermind.)

Make yourself a ~/Library/KeyBindings directory then place this file shown below into that directory. You should have instantaneous emacs key bindings system wide or maybe cocoa-wide! It's fabulous, if you enjoy emacs. Even if I were into vi, having these bindings, same as most default shells would still bring a smile to my face.

/* Picked up from Help search on Key Bindings.  Good stuff -shane */
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
        "~f"="moveWordForward:";
        "~b"="moveWordBackward:";
        "~<"="moveToBeginningOfDocument:";
        "~>"="moveToEndOfDocument:";
        "~v"="pageUp:";
        "~d"="deleteWordForward:";
        "~^h"="deleteWordBackward:";
        "~\010"="deleteWordBackward:"; /* Alt-backspace */
        "~\177"="deleteWordBackward:"; /* Alt-delete */ 
        /* Escape should really be complete. */
        "\033"="complete:"; /* Escape */
}

I don't know where any of these are bindings (i.e. "moveWordForward:") are defined so if anyone finds out. Let us know! It seems this file contains the answers to this question, many thanks to Mishka Gorodnitzky for this link and the link to TextExtras.

I was editing a Word document for work today, and I realized if I had these bindings in Word I would have a much more pleasant experience. I'm actually excited at the prospect of using Word! What an odd thing to hear myself think outloud.

- shane (at) terraspring.com


Talking cat? Only on OS X!

Here's a little hack I did on cat for my own amusement. Since we have speech synthesis by default on MacOS X, well, we might as well show it off. Apply this patch to the cat directory after you unpack this tarball. I didn't bother with Makefiles or the build system to try and figure out how to go about compiling it the "proper" way. Here's the compile line you have to stammer out to get it:

$ tar xfz text_cmds-1997.11.10-8.3.tar.gz
$ cd text_cmds-8-3
$ patch -d cat < /cat.diff; # or where ever you put the diff file
$ cd cat
$ cc -I/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/Headers -framework ApplicationServices cat.c -o cat

That's it! Give it a whirl.

$ ./cat -a
hi
[speaks it]
hi

If you decide to install it, I would recommend renaming your old cat binary file to something like cat.old just incase you ever need it back for some reason. Anyway, I should be doing other things like sleeping. ;)

-shane (at) terraspring.com

Update: Here's a binary and man page for the lazy of you out there. :)