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.
Could it be that you are accidentally hitting the input source switching shortcuts? If so, you can disable them in the System Preferences.
Also, if you find that the input language changes when you switch apps, this is actually normal behavior. By choosing “Use the same one in all documents” in the input source options, you can greatly decrease the chances of this happening. (With the exception of a few apps that seem to ignore/override this setting. Very annoying.)
If you've experienced this problem only when using Japanese keyboards, then I guess there is a different cause. I use US keyboards, but this unintended switching happens to me too. Mostly when switching to Adobe apps.
Best Answer
One way to maximize the ease of changing the spellcheck language is to use an app which allows you to synchronize the keyboard layout and the spellcheck dictionary. I think both Nisus Writer and Mellel have this feature.