In Mac OS X, there is a keyboard shortcuts to switch between activated input sources.
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.
I present to you, the ugliest possible "solution":
Ctrl-F8
is defined for Move focus to status menus in System Preferences » Keyboard » Keyboard Shortcuts » Keyboard & Text Input.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.
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".
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.
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.
Found kawa - quite simple app to fulfill exactly your needs. Setup shortcuts to directly switch to needed input source.
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
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.
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,