Binding key combinations to specific input source languages in OS X

After 4.5 years of struggling with OS X’s input source menu, I have finally figured out how to bind key combinations to selection of specific input sources (read: English, traditional Chinese through Pinyin, Japanese Hiragana, …).  Here are the steps:

  1. Note the specific names of the input sources on the input menu you want to use.  Mine, for example, are “U.S.”, “Russian”, “Pinyin – Traditional”, “Hiragana”, and so forth
  2. Install Quicksilver.
  3. Open Script Editor (Spotlight will find it).
  4. Within Script Editor, add the contents
    on changeKeyboardLayout(layoutName)
        tell application "System Events" to tell process "SystemUIServer"
            tell (1st menu bar item of menu bar 1 whose description is "text input") to {click, click (menu 1's menu item layoutName)}
        end tell
    end changeKeyboardLayout
    changeKeyboardLayout("your_input_source_name")
    

    where your_input_source_name is replaced with the name of one of your input sources. For example, I might use Pinyin - Traditional. Note that you have to get the name of the input source EXACTLY right.

  5. Save this script as your_input_source_name.scpt in a location of your preference, where you replace your_input_source_name with a mnemonic string of your preference (I might just use chinese-traditional) .
  6. Open Quicksilver through Spotlight.  Push ⌘’ to open the Triggers window.
  7. On the bottom of the Triggers window, hit “+” and choose HotKey to add a HotKey binding.
  8. For “select an item”, type in the name of your saved script until Quicksilver finds it.
  9. For “Action”, just leave it as “Run”.
  10. Don’t put anything for Target.  Click Save.
  11. You’ll now have a new item in the Triggers window called Run Script: your_input_source_name.scpt.  Now double-click on the “Trigger” column of that item, click “Settings” in the new sub-window popping out to the left, click in the Hot Key window, and type in a hot key combination (e.g., I might use ^⌘T).
  12. Repeat steps 4-11 for each input source for which you want a keyboard shortcut.

Kudos to Asmus who posted the very simple AppleScript code used above at this link.

Post a Comment

You must be logged in to post a comment.