Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Keyboard shortcut to switch _TO_ input source?

Hi,

I work in a multi-lingual environment, so I constantly have to switch between four different input source. (Qwerty keyboard, Dvorak keyboard, and two chinese input methods.) Previously I have been using the system hotkey of CMD+space and CMD+OPT+space, but to juggle between four sources this turned out to be a little messy.
I followed this link and set up a temporary solution:

https://quote.ucsd.edu/rogblog/2011/02/27/binding-key-combinations-to-specific-i nput-source-languages-in-os-x/

Though since it works with the UI, It gets laggy and somewhat problematic when the system gets intense. So I am wondering, deos anyone know of a more elegent way to do that, through a deeper level?

Thanks.

MacBook Pro, Mac OS X (10.6.8), Late 2008

Posted on Jun 15, 2012 9:28 PM

Reply
9 replies

Jun 17, 2012 8:13 AM in response to Sean Schü

Hi,


If you have installed "Xcode", here's the solution :

Create a plain text file with this code:

-----------------------------------------

#import <Foundation/Foundation.h>

#import <Carbon/Carbon.h>

int main (int argc, const char *argv[]) {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

BOOL b = NO;

NSString *inputID;

NSMutableString *thisID;

TISInputSourceRef inputSource = NULL;

if (argc < 2) b = YES; else inputID = [NSString stringWithUTF8String:argv[1]];

CFArrayRef availableInputs = TISCreateInputSourceList(NULL, false);

NSUInteger count = CFArrayGetCount(availableInputs);

for (int i = 0; i < count; i++) {

inputSource = (TISInputSourceRef)CFArrayGetValueAtIndex(availableInputs, i);

CFStringRef type = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceCategory);

if (!CFStringCompare(type, kTISCategoryKeyboardInputSource, 0)) {

thisID = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID);

if (b) {

printf("%s\n", [thisID UTF8String]);

} else if ([thisID isEqualToString:inputID]) {

b = YES;

OSStatus err = TISSelectInputSource(inputSource);

if (err) printf("Error %i\n", (int)err);

break;

}

}

}

CFRelease(availableInputs);

if (!b) printf("%s not available\n", thisID);

[pool release];

return 0;

}

-----------------------------------------

Save it in the Desktop with this name "changeInputSource.m" , use the encoding "Unicode (UTF-8)".


In the Terminal copy/paste this text :

cd ~/Desktop; gcc "changeInputSource.m" -o "changeInputSource" -l objc -framework foundation -framework carbon

Press the Return Key.


Move the executable file "changeInputSource" in the Applications folder or a folder of your choice.


This executable uses the Input Source identifier instead of the name.


script AppleScript examples :

To get these identifier.

-----------------------------------------

-- get all available Keyboard input source ID

set executablePath to quoted form of "/Applications/changeInputSource"

do shell scriptexecutablePath

-----------------------------------------



Change the Keyboard Input Source to "US"

-----------------------------------------

set executablePath to quoted form of "/Applications/changeInputSource"

set inputSourceID to "com.apple.keylayout.US"

do shell scriptexecutablePath&" "&inputSourceID

-----------------------------------------


Change the Keyboard Input Source to "Wubi Xing"

-----------------------------------------

set executablePath to quoted form of "/Applications/changeInputSource"

set inputSourceID to "com.apple.inputmethod.SCIM.WBX"

do shell scriptexecutablePath&" "&inputSourceID

-----------------------------------------


If you don't have Xcode, I can give you the link to download this executable.

Jun 19, 2012 7:14 PM in response to Sean Schü

Hi,


Sean Schü wrote:


Downloaded Xcode, installed it, but I'm still fighting to get gcc to work.

Can I have the compiled file?

Thanks.


Here is the link : changeInputSource.zip


This executable work on Mac OS X 10.5+, but i dont know on OS X 10.8, Apple has declared the Carbon APIs deprecated in OS X 10.8 Mountain Lion, which is to be released in July 2012.

Jun 22, 2012 10:53 AM in response to Sean Schü

Sean Schü wrote:


It worked, though with chinese input method there are still some hiccups. The trigger works beautifully and switches me to the input methods at a keystroke, though it seems like it only switches to the input mode instead of firing up the input method. I am assuming this has something to do with the Carbon APIs?


OK,


I add this line before TISSelectInputSource in the code :

TISEnableInputSource(inputSource);

I think this change should fix this problem.



Download it using the link in my other post.

Keyboard shortcut to switch _TO_ input source?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.