Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a keyboard method for opening the Mac's On-screen Keyboard. I could be a Terminal command. The string will be injected into user's Mac's USB port by our device; "Voila, an OSK!"

share|improve this question

See this solution for Mac OS X 10.6.

On Mac OS X 10.5, you can open the following program:


share|improve this answer

At least in 10.7 and later you can just open the KeyboardViewer application:

open -a KeyboardViewer

It has a few drawbacks though:

  • If you close the keyboard window by for example pressing the close button, the KeyboardViewer process stays running and keeps using something like 0-10% CPU.
  • If you open KeyboardViewer again after that, it doesn't reopen the keyboard window.
  • The keyboard window is made visible when I run scripts that emulate keystrokes or use Alfred's clipboard history.

All of those can be avoided by opening the keyboard window from the input menu:

tell application "System Events" to tell process "SystemUIServer"
    tell (menu bar item 1 where description is "text input") of menu bar 1
        click (menu item 1 where title ends with "Keyboard Viewer") of menu 1
    end tell
end tell

A workaround for the second issue is to terminate KeyboardViewer if it is running but has no windows:

if application "KeyboardViewer" is running then
    tell application "System Events" to number of windows of process "KeyboardViewer"
    if result is 0 then
        quit application "KeyboardViewer"
        delay 0.1
        activate application "KeyboardViewer"
        quit application "KeyboardViewer"
    end if
    activate application "KeyboardViewer"
end if
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.