Switching spelling languages
If you’re like me, then you probably write one email in language X and another one in language Y and you’re getting tired of always switching the spell checker language to stop every word being underlined in red. That means pressing command + shift + “:”, selecting the correct language and then close the spell check window since it consumes precious screen real estate.
So of to Google to find a simple utility which could switch languages faster and a bit more user friendly. Disappointingly, I couldn’t find any. The closest I found (although I have to admit I didn’t search very long) was using a applescript on MacOSXhints.
Having a bit of free time during the Christmas festive season, I decided to make such a utility myself. This shouldn’t be hard.
I first tried if I could achieve something by using the NSSpellChecker API. I had some hopes that I could set my preferred language system wide by using this API. However it quickly became clear that making any changes using the NSSpellChecker API stayed local to my own application and that I couldn’t use this API to change the language of e.g. mail.app. Bummer.
So I took a look again at the applescript solution and decided to make a standalone CoCoa application around it. As it turned out, this introduced some new problems.
The applescript solution as presented in the MacOSXhints forum hardcodes the 2 languages you want to switch to and you always need run the applescript which seemed hardly a user improvement to me. What I wanted was a small utility that nested itself in the status bar allowing to quickly switch to another language using a drop down menu. To make it a bit more user friendly, the last 2 languages I switched to, would automatically become the first 2 entries in the menu.

The first problem I encountered was the strange difference between the display names of the languages as they were returned by OS X and the shown languages in the spelling window.

For the applescript to work correctly, you really need to tell the popup menu to select e.g. “Australian English” instead of “English (Australia)”. A simple solution could be to use a simple lookup table. However that would open another can of worms. Depending on the language you are using OS X, the name of language in use will be localized to your preferred language. E.g “Australian English” would become “Australisch Engels” in Dutch. To make it even more fun. Suppose you’re writing an email using the Dutch language setting of OS X then you would indeed see the Dutch localized display name (”Australisch Engels”). However, open the spelling window in e.g. Xcode and you will see the English display name (”Australian English”) simply because Xcode hasn’t been localized for Dutch. Trying to solve this becomes a small nightmare if you want to support a lot of languages.
I found a rather simple workaround for this. Looking more closely to the menu in the above screenshot, you’ll see that the order of the languages stays the same. If I select item 1, I will always select “Australian English” no matter what language my OS X is running at that moment.
Another [related] problem then pops up. The applescript looked for a window with the title “Spelling and Grammar”. This is fine when you only use the English version of OS X, but in other languages, this window gets a localized name and the applescript doesn’t work anymore. Below you can see the same window for Dutch, English, French and German (the 4 most used languages in Belgium, in alphabetical order).




So I modified the applescript to look for one of those windows and if one of them exist to perform the click on the popup menu, select the wanted language and close the window again.
Important: If the application doesn’t work, check in System Preferences -> Universal Access if support for assistive devices is allowed. Make sure that the checkbox for “Enable access for assistive devices” is checked.

You can download a small Xcode project (Leopard only) which should work fine for Dutch, English, French and German localized versions of OS X. It should be straightforward to add any language you want.
This small tool is certainly not going to win any beauty contests (using applescript means that you will see the spell checker window open and close again which is a bit annoying) but it does get the job done for me.
Xcode project can be downloaded here: spellingSwitcherProject.zip
A prebuilt application can be downloaded here: spellingSwitcherApplication.zip
Posted: December 27th, 2008 under CoCoa.
Comments
Comment from Felipe Pait
Time January 31, 2009 at 4:14 pm
This is sweet, thanks! Badly missing feature….
I started having trouble with the MacOSXhints script in Leopard, now I see there are recent contributions, but your app does the trick nicely.
One question: do I have to double click spellingSwitcher.app every time to switch, or can the option somehow stay in the status bar?
Comment from kvnieuwe
Time January 31, 2009 at 6:52 pm
@Felipe Pait
You can leave the app open all the time. On my Mac, I added it to my login items (preference panel -> Accounts -> Login Items). So each time I boot it places itself in the statusbar. Each time I want to switch to another language I can immediately go to the statusbar without double clicking the app.
PS. I noticed that your blog seems to be written in Brazilian Portuguese. I assume you run OS X in English otherwise the app can’t work. I have a short explanation in the blog why this is (the title of the spelling window is language dependent and the script needs the exact name unfortunately).
Comment from Felipe Pait
Time January 31, 2009 at 10:43 pm
Got it. It was not appearing because my status bar was too crowded. I used the opportunity to clean it up, now it stays visible. It seems that the menu bar item for the app cannot be moved by command dragging. Something to do if you change your mind and decide to go for the elegance prize
Correct and correct - I write in Portuguese and English with OSX in English. I read the exaplanations. But the easiest thing was to use the app as is…… The main thing is that I’d wanted this for a long time, and now I have it. Thanks!
Write a comment
You need to login to post comments!
Comment from Jasper
Time December 29, 2008 at 1:11 pm
Brilliant! I had been looking for a good solution for this very same problem as well and this fits the bill perfectly, thank you!