Mac Mountain Lion on screen keyboard

Is there a way that, when you switch language inputs for your keyboard, the onscreen keyboard will automatically show up?


I asume you want to show an onscreen keyboard when changing your keyboard layout. One obvious approach is to use AppleScript, and that is what I've done here. I think this approach is not error prone, but it works.

At first, in the Systems preferences select the keyboards you want to use, and make sure you tick 'Show Input in menu bar' System Preferences -> Keyboard -> Input Sources

Then check if your languages are available in the 'Input menu' in the top right corner of your menu-bar.

Keyboard input source name

So, now the keyboards are available from the menubar. We can use applescript to invoke with the menubar and start your onscreen keyboard.

(* A function to change the language and activate the keyboard app *)
on changeKeyboardLayout(layoutName)
    (* Close the current language keyboard app *)
    tell application "KeyboardViewer"
        quit
    end tell
    (* Change the keyboard layout *)
    tell application "System Events" to tell process "SystemUIServer"
        tell (menu bar item 1 of menu bar 1 where description is "text input")
            click
            click menu item layoutName of menu 1
        end tell
    end tell
    (* Open the new language keyboard app *)
    tell application "KeyboardViewer"
        activate
    end tell
end changeKeyboardLayout

(* Call the function with the keyboard name as variable *)
changeKeyboardLayout("U.S. Extended")
(* changeKeyboardLayout("Canadian English") *)
(* changeKeyboardLayout("U.S.") *)

You can use Automator to make an Application or a Service of this AppleScript and and even attach a keystroke to it.