A script for a clipboard dictionary lookup tool

Nov 19, '03 10:01:00AM

Contributed by: BulbVivid

First off, I know nothing about what I've done except that it works for me. I can't even call myself a novice when it comes to computer languages. The script I've cobbled together likely could be done better, or may even have been done before. But I looked around and couldn't find anything that did what I needed, so I came up with my own.

I needed an easy way to look up words in online dictionaries. Fooling around with a few scripts that did pieces of what I wanted, I concocted one that searches for whatever you have copied to the clipboard. I use it to search Merriam-Webster's Unabridged and Google, but the script can be adapted to whatever URL you want to use.

Though the script can be saved as an app and run each time you use it, I use iKey to assign keys to run the script (arbitrarily Command-G and Command-Shift-G for me). That way, I just highlight and hit a couple of keystrokes and the selection shows up in the browser. Though there are a few shortcomings (doesn't seem to like special characters), it does a pretty good job. Here's the AppleScript, hope it works for others.


tell application "Safari"
  activate
  if not (exists document 1) then
    make new document at the beginning of documents
  end if
  delay 0.6
  set page_info to the clipboard
  set page_url to "http://www.google.com/search?hl=en&q=" & page_info
  set URL of document 1 to page_url
end tell
[robg adds: We've covered dictionary stuff before, but this one was unique enough that I felt it worth sharing. Of course, you can use the freeware OmniDictionary as well, and it installs a Services menu item for easy use.]

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031111202259919