23

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.

  • 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
6

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.

  • 1
    @Nikem Did it work? – Daniel Beck Dec 21 '10 at 9:53
  • 1
    Yes, it worked. – Nikem Dec 21 '10 at 19:45
  • 1
    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
  • @Daniel In fact, I don't know which answer to recommend. I have chosen mine, but yours is more widely usable... – Nikem Dec 22 '10 at 11:56
11

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".

  • Definitely nicer than mine. I really should learn my AppleScript properly. – Daniel Beck Jan 22 '11 at 16:24
6

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.

4

I know it's an old question. But even in the end of 2016, I still didn't find a simple and nice solution. Therefore, I made IMEShortcuts, works on Sierra. You can assign a customized shortcut for any specific input method. Please give it a shot. And if you guys find any bugs, I would happy to help.

Also, Karabiner (known as KeyRemap4MacBook) is a great keyboard customizer for Mac. But it's a little bit complicated and currently broken on Sierra. If you're using Yosemite or El Capitan, it would be another nice choice.

  • Thanks for IMEShortcuts! It's very nice. I'd gladly pay $5 or so for it if you added icons to the menubar to show active language (so I wouldn't need to have BOTH IMEshortcuts and the app icon in my menubar taking up space). I would also like to be able to customize the icon used—for example I want to use the Canadian French input because it's closer to US QWERTY, but I want to see a French flag because a Canadian flag doesn't symbolize "French" to me. Those things would make it awesome! – iconoclast Oct 26 '18 at 19:47
1

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

  • 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
  • I'm having hard time finding how to set this up with Karabiner. – Ivan Balashov Apr 30 '16 at 14:38
1

On AppleScript you must only take cmd + "space" (or something other, what you change keyboard source).

And all what you need:

    key code 49 using command down

49 - code of 'space' button in ASCII for AppleScript.

P.S.: don't forget get access for you AppleScript utility in System Preferences.

1

Found kawa - quite simple app to fulfill exactly your needs. Setup shortcuts to directly switch to needed input source.

  • 1
    Welcome to Super User. Please read How to Recommend Software then edit your answer to include at least the minimum required information (the items in bold). Posts without this information may be subject to deletion. Thanks for contributing. – Twisty Impersonator Jan 20 at 12:38
0

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,

  • 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

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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