26 May 2011

Changing keyboard layout on Mac OSX

If you are multilingual, or you have multilingual friends and want to use multiple languages on your Mac, the first thing to complain about is the keyboard shortcut that changes the keyboard layout. Or in simpler terms: "Why on earth doesn't Apple let you use alt+shift to change language?". I've just cooked up an easy hack :D.

1. Set up an Apple-approved keyboard shortcut to change the keyboard layout. I use Command+space. This usually conflicts with the Spotlight shortcut; I've changed that to control+space.

2. Install KeyRemap4MacBook.
3. From the KeyRemap's preferences (Misc & Uninstall) open and edit private.xml (unless the developer includes this hack to the bundled ones). Your private.xml should be like this:
<?xml version="1.0"?>
<root>
<item>
  <name>Shift + Option_L to Command_L+Space</name>
  <name>Option_L + Shift to Command_L+Space</name>
  <identifier>itsomp</identifier>
  <autogen>--KeyToKey-- KeyCode::OPTION_L, ModifierFlag::SHIFT_L | ModifierFlag::OPTION_L | ModifierFlag::NONE, KeyCode::SPACE, ModifierFlag::COMMAND_L</autogen>
  <autogen>--KeyToKey-- KeyCode::SHIFT_L, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::NONE, KeyCode::SPACE, ModifierFlag::COMMAND_L</autogen>
</item>
</root>
4. Reload the XML file (Change Key -> Reload XML)

5. The new options should be right at the top. Activate it and you're done:

You can now let other people use your Mac without having to endure the "why does Apple have to do everything differently?" questions.