Is there a way that, when you switch language inputs for your keyboard, the onscreen keyboard will automatically show up?
Mac Mountain Lion on screen keyboard
displaykeyboardscreen
Related Solutions
OK, building off of a post on SuperUser, here goes:
You can create AppleScripts to change to the various languages. If you make Services that take no input and just call this one script, they'll all live happily in the Services menu when you want them. Otherwise, use your AppleScript trigger method of choice.
To switch to, say, Greek, and bring up the keyboard viewer when you do, run this script:
tell application "System Events"
if exists process "Keyboard Viewer" then
display alert "running"
try
tell application "KeyboardViewer" to quit
end try
end if
end tell
tell application "Finder"
open item "System:Library:Input Methods:KeyboardViewer.app" of the startup disk
end tell
changeKeyboardLayout("Greek")
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
To switch back to the U.S. layout, killing the viewer when you do, use this:
tell application "System Events"
if exists process "Keyboard Viewer" then
display alert "running"
try
tell application "KeyboardViewer" to quit
end try
end if
end tell
changeKeyboardLayout("U.S.")
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
Substitute the names of whatever keyboard layouts you want in the changeKeyboardLayout("layout name")
command.
Launch Keyboard Viewer with a Service (Improved)
You can launch the Keyboard Viewer with a shortcut by using Automator and the OS X Services functionality.
The Keyboard Viewer program lives at /System/Library/Input Methods/KeyboardViewer.app
(in versions prior to Lion, it may be at /System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/KeyboardViewerServer.app
). You open it with a hotkey by using Automator to create a simple launcher service.
- Open Automator and select Service as the type of your new document.
- Set the options (at the top of the workflow area) to "Service receives no input in any application".
Add the Run AppleScript action to your workflow, and replace the text with the following lines:
if application "KeyboardViewer" is running then quit application "KeyboardViewer" end if activate application "KeyboardViewer" -- wait until the window has been closed, then end the KeyboardViewer process set numberOfWindows to 1 repeat until numberOfWindows = 0 delay 5 tell application "System Events" tell process "KeyboardViewer" set numberOfWindows to count windows end tell end tell end repeat quit application "KeyboardViewer"
- Save with a name like "Open Keyboard Viewer", then open Keyboard Preferences to the Keyboard Shortcuts tab. Select Services in the left pane and scroll to the bottom, where you should see the name of your Service under the General Section.
- Make sure the box is checked to enable it, then select it and click add shortcut to set a hotkey.
- After setting the hotkey, open the Services menu in any application (i.e. Finder > Services), then close it. For some reason my hot key didn't work until I did this.
A couple notes:
- The script requires that you check the Enable access for assistive devices box in the Universal Access preference pane.
- Closing the Keyboard Viewer window doesn't actually quit the application, and as Lri points out, it can be a bit of a resource hog, so the
repeat
loop checks every 5 seconds if Keyboard Viewer has any open windows, and if not, quits the process. - If you're running a pre-Lion OS, you may need to replace the instances of
KeyboardViewer
withKeyboardViewerServer
. I don't have anything pre-Lion handy to test this (if someone else could report back in the comments, that would be great. - Because the script loops until the Keyboard Viewer is closed, the Automator spinning gear icon will show in the menu bar until it closes.
Related Question
- MacOS – Change main keyboard layout in OS X
- Switch input language depending on physical keyboard attached
- MacOS – Screen overlay when using hotkey to switch keyboard input
- IPad – Turn off iPad on-screen keyboard using Microsoft Designer Bluetooth Desktop Keyboard
- Keyboard – How to Switch Fn Function Key Language
- Mac – Onscreen keyboard at startup
Best Answer
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'
Then check if your languages are available in the 'Input menu' in the top right corner of your menu-bar.
So, now the keyboards are available from the menubar. We can use applescript to invoke with the menubar and start your onscreen keyboard.
You can use Automator to make an Application or a Service of this AppleScript and and even attach a keystroke to it.