Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Mac OS X, there is a keyboard shortcuts to switch between activated input sources.

alt text

Is it possible to switch to a specific language? So if you have 3 input methods, you could have 3 shortcuts: Ctrl-1 for English, Ctrl-2 for Spanish and Ctrl-3 for Russian.

share|improve this question
    
Keyboard layout and interface language are independent. And since interface language only applies after restarting a program, anything you gain by a shortcut would be negated by the requirement to restart applications anyway. –  Daniel Beck Dec 20 '10 at 19:09
    
I am not interested in changing interface languages. Only input languages are of interest. –  Nikem Dec 20 '10 at 19:13
    
I streamlined and clarified your question. Please revert if you think I did something wrong (I'm new to doing this). –  Daniel Beck Dec 20 '10 at 19:41

5 Answers 5

up vote 3 down vote accepted

I present to you, the ugliest possible "solution":

  • Enable support for assistive devices in System Preferences » Universal Access,
  • and displaying the Input Sources menu in the menubar in System Preferences » Language and Text.
  • Make sure the shortcut Ctrl-F8 is defined for Move focus to status menus in System Preferences » Keyboard » Keyboard Shortcuts » Keyboard & Text Input.
  • Make sure the Input Sources menu is the leftmost menu item that can be moved by dragging while holding Cmd down.

Use AppleScript Editor and write three scripts, each of them with the following code:

tell application "System Events"
    key code 100 using control down # press Ctrl-F8
    delay 0.5 # wait a bit, UI might be slow
    key code 125 # press down to open the menu
    keystroke "german" # name of your desired language, in my case tested using German
    key code 36 # press enter
end tell

Save once for each language, switching out the name of the language. If you want to press different keys, or assign something different from Ctrl-F8, substitute with the key codes here. You can also move the Input Sources menu from its leftmost position by inserting a few right arrow key presses.

Invoke scripts however you want, e.g. use your application launcher (Quicksilver, Launchbar etc.), or wrap them in Services using Automator, and assign them keyboard shortcuts in System Preferences » Keyboard » Keyboard Shortcuts » Services.

share|improve this answer
    
Thank you :) I'll give it a try. –  Nikem Dec 20 '10 at 21:50
    
@Nikem Did it work? –  Daniel Beck Dec 21 '10 at 9:53
    
Yes, it worked. –  Nikem Dec 21 '10 at 19:45
    
Anda, Daniel, although I have chosen another solution, thank you nevertheless for introducing me to Action Script and Services :) –  Nikem Dec 21 '10 at 19:52
    
@Nikem You're welcome. Please up-vote my answer by clicking the "up arrow triangle" next to it if you find this answer useful. You can also accept an answer (indicating it is the one answer you like best, and consider your problem solved) by clicking the tick mark next to it. By the way, ActionScript is Adobe, this is AppleScript. –  Daniel Beck Dec 21 '10 at 19:55

I came up with a bit nicer solution in AppleScript, given you know the name of the Keyboard Layout you want to switch to. Create a function like this:

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

and then call it by

 changeKeyboardLayout("English")
 changeKeyboardLayout("German")

Be aware that the names of Keyboard Layouts are localized, i.e. on a german system the above example would need to call "Englisch" and "Deutsch".

share|improve this answer
    
Definitely nicer than mine. I really should learn my AppleScript properly. –  Daniel Beck Jan 22 '11 at 16:24

I have another solution that has satisfied me the most. KeyRemap4MacBook is application that allows you to remap your keyboard buttons. Among other things it allows for some, not at all exhaustive, support for language change. So we some custom configuration it does what I want.

Cons: - third party application - only limited language support for now

Pros: - Conceptually a little bit nicer that running script on UI

share|improve this answer
    
I didn't find anything related to flexible use of input sources on the web site, only some hard-coded actions related to russian/english. Can you elaborate? –  Daniel Beck Dec 21 '10 at 19:57
    
It's not flexible. It just happens that it supports switching to english and russian (and now estonian), which are the languages I needed. And it allows you to map arbitrary key combinations to those actions. Switching to language in my case. –  Nikem Dec 22 '10 at 10:44

One option would be to download changeInput and assign shortcuts to shell commands like changeInput U.S..

You could also use KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <vkchangeinputsourcedef>
    <name>KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA</name>
    <inputsourceid_equal>com.apple.inputmethod.Kotoeri.Japanese</inputsourceid_equal>
  </vkchangeinputsourcedef>
  <item>
    <name>change_inputsources</name>
    <identifier>change_inputsources</identifier>
    <autogen>__KeyToKey__ KeyCode::E, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_ENGLISH</autogen>
    <autogen>__KeyToKey__ KeyCode::H, VK_OPTION | ModifierFlag::NONE, KeyCode::VK_CHANGE_INPUTSOURCE_HIRAGANA</autogen>
  </item>
</root>

See the private.xml documentation.

VK_CHANGE_INPUTSOURCE_ENGLISH is defined in vkchangeinputsourcedef.xml. You can see the IDs of input sources from EventViewer.app. Without | ModifierFlag::NONE for example the first setting would also apply to option-command-E. See the source for the key code values and predefined settings.

share|improve this answer

This link has a video on how to do it. It already has a hotcake with is "command + space", but the spotlight hot-key is also "command + space". Spotlight over-riders the hot-key, so the language switch doesn't occur. The video in the link will show you how to change the hot-key so that you can toggle the hot-key.

Good Luck,

share|improve this answer
1  
He already knows how to switch between languages, he wants to switch to a specific one, since he probably has more than 2 activated. –  Daniel Beck Dec 20 '10 at 19:08
    
Yes, exactly as Daniel said. I have 3 input languages and need to to select a specific one. –  Nikem Dec 20 '10 at 19:14
    
Sorry... I must have misunderstood the question. I thought you were trying to make a way to toggle between languages with a hot-key. –  David Dec 20 '10 at 21:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.