Ever since upgrading to Snow Leopard, one function I’ve missed is the ability to toggle the Keyboard Viewer on and off with an applescript.
It looks like Apple modified the Keyboard Viewer utility for Mac OS X 10.6 (or a possible tablet, who knows…) and the old applescripts don’t work.

I’ve finally come across a method for getting this to work in Snow Leopard again, although it’s not as easy as it was in Leopard, and it seems to be as slow as hell to open.

Check out Nicholas Riley’s tiny app (only 6 lines of custom code!) that fixes this:
http://github.com/nriley/keyboardViewer (download)

Once that’s downloaded and installed (you need to go into terminal and move it, or just navigate to /usr/local/bin/ and paste it there), you can then use the applescript listed on the App’s homepage to get it working in applescript.

tell application "System Events"
if exists (process "Keyboard Viewer") then
click process "Keyboard Viewer"'s window 1's buttons whose subrole is "AXCloseButton"
else
do shell script "/usr/local/bin/keyboardViewer"
end if
end tell

I have modified this slightly, as the ‘click process’ part of the applescript uses a deprecated method (Apple’s own fault) and could become obsolete at any point. I just used a simple killall command in its place


tell application "System Events"
if exists (process "Keyboard Viewer") then
do shell script "killall KeyboardViewer"
else
do shell script "/usr/local/bin/keyboardViewer"
end if
end tell

And now, my trusty Cmd + Optn + Ctrl + K Quicksilver trigger is back!