Random Ubuntu tip of the day—Spell check everywhere

Note: this post isn’t too user-friendly, so beware.

I’ve heard that Macs have a nice global spell-check system. I’ve never used a Mac, but having a single spelling checker at the OS-level seems like a good idea. You won’t need to train the spell-checks embedded in each application individually.

I used to have a hack on Windows that provided decent global spell checking. It’s much more easier on Linux.

First run these commands:

sudo aptitude update
sudo aptitude -y install aspell aspell-en xclip

That installs aspell, a really nifty command-line spell checker, and xclip, a utility to manipulate your clipboard. Once you have these tools installed, copy-paste the following to a text file:

#!/usr/bin/env bash
# Copy clipboard contents to a temp file
xclip -o > /tmp/spell.tmp
# Run aspell on that file
aspell check /tmp/spell.tmp
# Copy the results back to the clipboard
cat /tmp/spell.tmp | xclip

Give the file a nice name, spellcheck.sh for instance. Mark it as executable.

chmod +x spellcheck.sh

Now that the script’s created, we need a convenient way to call it. The easiest method to do so is to create an alias for running it in your Bash init script. Run:

gedit ~/.bashrc

And add the line:

alias spellcheck='gnome-terminal -x ~/Path/To/Your/spellcheck.sh'

at the bottom of the file. Now anytime you need to run it, just copy your text, and type spellcheck from your terminal. If you don’t have a terminal window open all the time (you really should), then do Alt-F2 to open the “Run Application” dialog box and type spellcheck there. You’ll get a nice little window like:

Screenshot of the spell checker

Options 1…9 are for suggested spelling corrections, i is used to ignore a word, r to replace it with another, a to add it to the dictionary. Once all your corrections are done, the window will close automatically and you can paste the result back to your application.

Creating a keyboard shortcut to launch it is left as an exercise for the reader.

PS: I’ve not used KDE yet, but I guess DCOP could extract text (selected or otherwise) from the currently open window and put it back in? That would be neat, reason enough to switch.

Comments (2)