Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script for a clipboard dictionary lookup tool System
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.]
    •    
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[4,260 views]  

A script for a clipboard dictionary lookup tool | 11 comments | Create New Account
Click here to return to the 'A script for a clipboard dictionary lookup tool' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A one-liner replacement
Authored by: THEM on Nov 19, '03 01:11:24PM
Replace all that with one line
open location \"http://www.google.com/search?hl=en&q=\" & (the clipboard)
--- -- The preceding message does not represent the views of the sender.

[robg adds: I edited the above code string to format properly in the What's New box...]

[ Reply to This | # ]
A one-liner replacement
Authored by: DougAdams on Nov 19, '03 02:12:49PM
This will work in Panther and Jaguar:

set theURL to open location "http://www.google.com/search?hl=en&q=" & (the clipboard)

try -- Jaguar default browser
	tell application "Finder"
		open location theURL
	end tell
on error -- Panther default browser
	open location theURL
end try


[ Reply to This | # ]
Oops...
Authored by: DougAdams on Nov 19, '03 02:15:33PM
My error.

set theURL to "http://www.google.com/search?hl=en&q=" & (the clipboard)

try -- Jaguar default browser
        tell application "Finder"
                open location theURL
        end tell
on error -- Panther default browser
        open location theURL
end try


[ Reply to This | # ]
Oops...
Authored by: THEM on Nov 19, '03 02:20:32PM

open location is in the standard additions, shouldn't need to be wrapped in a tell block.

---
--
The preceding message does not represent the views of the sender.



[ Reply to This | # ]
Oops...
Authored by: DougAdams on Nov 19, '03 04:25:56PM
open location is in the standard additions, shouldn't need to be wrapped in a tell block.

Of course you are correct. My example was from memory; from a situation where the default browser wouldn't activate in Jaguar unless the tell block was used.

[ Reply to This | # ]
A script for a clipboard dictionary lookup tool
Authored by: BulbVivid on Nov 19, '03 06:43:20PM

Thanks y'all . . . like I said, I cobbled that script together with bits from a few that did pieces of what I want.

After seeing it here, I checked out OmniDictionary, but I'm a book editor, and we use specific dictionaries (namely Merriam-Webster) that I couldn't get to work with Omni, nor does it google what's in the clipboard (very handy for research).

But, mostly because I don't know what I'm doing and there seems to be a lack of Mozilla scripts to use as examples, I couldn't get it to work with Mozilla, and your examples do.

I appreciate the help and the replies. I was bummed that I couldn't get the script to work with Mozilla--that browser absolutely flies. Now my definitions won't have to wait even an instant to appear. Woo hoo!

Thanks,
Jason



[ Reply to This | # ]
A script for a clipboard dictionary lookup tool
Authored by: BulbVivid on Nov 19, '03 06:48:30PM

Hey guys,

Is there anyway to make the URL open in the existing window or tab? Right now (with your examples), it opens a new window every time.

Thanks,
Jason



[ Reply to This | # ]
dictionary address
Authored by: snown on Nov 23, '03 04:41:31PM

I noticed that all of the scripts presented talk about the google look-up feature, but none list the URL used to look up the words for the dictionary. Can someone help me by listing that URL here? thank you.



[ Reply to This | # ]
dictionary address
Authored by: BulbVivid on Nov 24, '03 08:53:44AM

The URL can be changed to whatever you want to use. I use M-W's subscription-based Unabridged Dictionary, so that URL won't do you much good unless you pay for the service.

The URL for M-W's Collegiate Dictionary is: "http://www.m-w.com/cgi-bin/dictionary?book=dictionary&va=" (the actual URL doesn't use quotes, though they're used in the script). You kind of have to experiment with whatever site you want to use to see how their URL works during searches. Though I don't know why (I'm sure there's a reason), most end with "=" followed by the search terms. For example, to adapt the script to use the AltaVista search engine, change the URL to: "http://www.altavista.com/web/results?q=".

Good Luck,
Jason



[ Reply to This | # ]
dictionary address
Authored by: snown on Nov 24, '03 06:40:53PM

thank you, that helped alot



[ Reply to This | # ]
dictionary address
Authored by: openmind on Nov 27, '03 01:52:57PM

From Tidbits 657 (www.tidbits.com)

1. Create new Bookmark

2. Where the bookmark's URL normally goes, paste the following script:
javascript:void(q=prompt('Enter word to look up.','')); if(q)void(location.href='http://dictionary.reference.com/search?q='+escape(q))

Make sure it is all in one line
Make sure javascript is turned on.

3. When you open this bookmark a little dialog box will open. Enter the work to lookup.
The results will open in the same page.
Tested this with Safari, Explorer and Camino



[ Reply to This | # ]