9 Replies Latest reply: Jun 23, 2012 6:03 AM by Sean Schü
Sean Schü Level 1 Level 1 (10 points)

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
  • Tom Gewecke Level 9 Level 9 (75,355 points)

    I have seen this question raised many times, but never seen a solution like you are seeking.  There is one app, Nisus Writer, which includes preferences settings that let you choose keyboard shortcuts to select language/keyboard/font all at once.

  • Sean Schü Level 1 Level 1 (10 points)

    I was looking for a system-level solution, but thanks.
    I guess will have to stick with what I have now, since this is the best solution available anywhere.

  • Jacques Rioux Level 4 Level 4 (2,695 points)

    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 script executablePath

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

     

     

    Change the Keyboard Input Source to "US"

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

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

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

    do shell script executablePath & " " & 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 script executablePath & " " & inputSourceID

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

     

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

  • Sean Schü Level 1 Level 1 (10 points)

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

    Can I have the compiled file?

    Thanks.

  • Jacques Rioux Level 4 Level 4 (2,695 points)

    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.

  • Sean Schü Level 1 Level 1 (10 points)

    Thanks, after two days of research I finally got the gcc compiler ( have to install Xcode, and then download it from downloadable content... can you believe it?) but it refuses to compile it for me, saying thare are stray stuff here and there.

    I'll give it a try and see how it works.

    Thanks a lot.

  • Sean Schü Level 1 Level 1 (10 points)

    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?

  • Jacques Rioux Level 4 Level 4 (2,695 points)

    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.

  • Sean Schü Level 1 Level 1 (10 points)

    Works like magic now. Thank you!