Toggle Character Palette and Keyboard Viewer on/off

Apr 02, '08 07:30:00AM

Contributed by: llee

This hint will let you toggle the state of the Character Palette and Keyboard Viewer via AppleScript and a hot key -- activate and hide the panels just by pressing their assigned hot keys. I'll use Proxi for the hot key assignments, but the AppleScripts should work with any such program -- Spark, Keyboard Maestro, Quickeys, Butler, etc. (This hint is similar to this earlier hint, but provides a toggle functionality and works in 10.5.)

Install Proxi, then open the Proxi Editor. Choose Insert Trigger » Hotkey Monitor from the Action menu beneath the Triggers portion of the Proxi Editor window (or drag it in there from the Components window). Replace the selected text (Hotkey Monitor) in the new Trigger with Toggle Character Palette. Click Set in the right half of the Editor window. Press Control-~ (tilde), or the key combination of your choice, to set the trigger's keyboard shortcut.

Choose Insert Task » AppleScript from the Action menu beneath the Tasks portion of the Proxi Editor window. (Double-click AppleScript in the Tasks portion of the window to rename it if you like.) Click Run Custom AppleScript in the right half of the Editor window. Copy and paste the following code into the Run Custom AppleScript text field:

set app_ to "CharPaletteServer"
--or if you don't trust Launch Services (I don't):
set proc_ to "/System/Library/Components/CharacterPalette.component/Contents/SharedSupport/CharPaletteServer.app/Contents/MacOS/CharPaletteServer"

try
  do shell script "ps -axwww | grep" & space & proc_ & space & "| grep -v grep"
  tell application app_ to quit
  on error
    do shell script proc_ & space & "> /dev/null 2>&1 &"
end try
Click Check Syntax to be sure the correct script source was pasted. Press the key combination you chose a couple of times to test the functionality. Hide Proxi by holding the Option key and clicking the desktop. Read on for the Keyboard Viewer version.

Follow the same steps as above to create a new Hotkey Monitor trigger in Proxi, name it Toggle Keybaord Viewer, assign a different keyboard shortcut, and set its custom AppleScript code to this:

set proc_ to "/System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/KeyboardViewerServer.app/Contents/MacOS/KeyboardViewerServer"
set app_ to "KeyboardViewerServer"
try
  do shell script "ps -axwww | grep" & space & proc_ & space & "| grep -v grep"
  tell application app_ to quit
  on error
    do shell script proc_ & space & "> /dev/null 2>&1 &"
end try
[robg adds: These both worked as described in my testing, using Butler as the vehicle. The original source code for both scripts can be found on the author's site.]

Comments (17)


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