Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I work with non-ASCII alphabets like Hebrew and Greek just a little bit, so I have the appropriate keyboard layouts available in the language and text menu in the top panel. However, I don't quite know all the characters yet, so I have to bring up the keyboard viewer when I want to type in those languages so that I can hunt for the characters I want. Is there a way to automatically bring up the keyboard viewer when certain keyboard layouts are selected and then make it go away when I switch back to normal?

share|improve this question
add comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

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.