10.3: Restore the Key Caps application via AppleScript

Feb 26, '04 07:02:00AM

Contributed by: jakacmar

From time to time, I need to take a peek at the Keyboard Viewer, but I despise having the Input Menu in my menu bar since it serves no other purpose for me and just takes up space. And for whatever reason, the Input Menu is the only keyboard extra to make heavy use of color, which I find distracting. Anyway, there's an application called "KeyboardViewerServer" located at /System -> Library -> Components -> KeyboardViewer.component -> Contents -> SharedSupport. Running this app opens the Keyboard Viewer pallete. However, if this app is already running (it is not quit when the pallete is closed) then "opening it has no effect."

So I wrote a short AppleScript that checks to see if this process exists, quits it if it does, and then launches KeyboardViewerServer. It's worked perfectly for me. I saved the script as an application, called it "Keyboard Caps" and put it in my Utilities folder. Now I can finally get rid of the input menu. Here's the script.

tell application "System Events"
  if exists process "KeyboardViewerServer" then
    try
      quit application "KeyboardViewerServer"
    end try
  end if
end tell

tell application "Finder"
  -- NOTE: Enter the following two lines as ONE LINE without spaces!
  open item "System:Library:Components:KeyboardViewer.component:
  Contents:SharedSupport:KeyboardViewerServer" of the startup disk
end tell
Now "Key Caps" is back in its original location.

[robg adds: The first couple of times I tried to compile this, it failed. I have no idea why, as after simply adding and removing a space from the script, it compiled and ran just fine...]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040218181307147