Expand Your Vocabulary with This Quick and Dirty AutoHotkey Tip Or Modify This Script for Any Web Page Search
This week in ComputorEdge Software Showcase I reviewed Visual Thesaurus which offers a clever way to search for and understand English synonyms. Anyone who does a great deal of writing (or merely wants to self-educate) needs a good thesaurus. While the vocabulary enhancement software fascinated me and I certainly found it uniquely useful, it appeared to be insulated from the usual AutoHotkey techniques. (Other than by first saving the result to a PDF, I found no easy technique for copying a word to the clipboard. Plus, when opening, the app does not accept preloading a search term.) Beyond launching the program with a Hotkey, I didn’t see a simple method for automating the program with AutoHotkey. Other Web thesaurus sites make it easier to launch replacement word searches.
With an online thesaurus, such as Thesaurus.com, automating word lookup with AutoHotkey takes only a few lines of code. (I would have offered this as a beginning level AutoHotkey tip but for the fact that the primary code in the Hotkey routine requires a little understanding of Clipboard techniques and the use of ErrorLevel—not that you need to know the purpose of all the code to use it. Merely changing the line of code in red in the snippet below alters the purpose of the Hotkey.)
After highlighting a word in any document, Web page, or editing field, the key combination CTRL+ALT+t (^!t) opens Thesauras.com in your default Web browser and searches for the highlighted word:
^!t:: ; open and Thesaurus.com
OldClipboard:= ClipboardAll
Clipboard:= ""
Send, ^c ;copies selected text
ClipWait 0
If ErrorLevel
{
MsgBox, No Text Selected!
Return
}
Run http://www.thesaurus.com/browse/%Clipboard%
Clipboard:= OldClipboard
Return
This routine includes what I consider the basic structure for an important clipboard technique in AutoHotkey. Use all the code except the one line shown in the color red (which you replace with a new specific action) to activate any program or subroutine with preselected text. The snippet copies the highlighted text to the Windows Clipboard for later use. It can alter text, open Web pages, run programs, or execute any other normal Windows function. In fact, in many scripts, you may want to put the bulk of the code into a user-defined function, then supply the action parameter shown in red:
ClipboardLaunch("Run http://www.thesaurus.com/browse/%Clipboard%")
But, we’ll leave that discussion for another time.
Although I first started my explorations into employing the Windows Clipboard for manipulating text and initiating action in A Beginner’s Guide to AutoHotkey, this previous blog offers the most detailed explanation of the working routine above and its various pieces. Therefore, I won’t repeat that information in this blog.
The routine copies the highlighted word to the Windows Clipboard, then inserts it into the URL for initiating a Thesaurus.com word search. To determine the proper format for this type of search you need to open the target site and run a search manually. For example, I loaded the site and searched for the word “highlight” which returned the results page as shown in the image below.

Thesaurus.com uses as its search URL:
http://www.thesaurus.com/browse/{search term}
The AutoHotkey script adds the search term found in the clipboard variable (%Clipboard%)—in this case, evaluated as “highlight.”
Not all Web sites use the same format. Another common search approach adds a question mark (?) followed by an equivalence. For example:
https://www.caloriecount.com/cc/search.php?searchpro=apple
looks up the number of calories in an apple on http://www.caloriecount.com. For the lookup to work, the search URL must match the format of the particular Web page.
This Hotkey routine saves time by loading the Web page and directly launching the search from any highlighted text. Change the target URL with the proper search format to modify this snippet to work with any Web page with a built-in search capability.
Next time, I implement the above techniques to highlight a cool (secret?) feature of the AutoHotkey support site making it an even better source of help when writing scripts. You will love this one!
Later, I put a number of searches (thesaurus, dictionary, AutoHotkey, calories) into a pop-up menu. This limits the number of Hotkeys you need to memorize.
* * *
If you find Jack’s AutoHotkey Blogs useful, then please consider contributing by purchasing one or more of Jack’s AutoHotkey books. The e-books make handy AutoHotkey references.