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

Define words via Google and AppleScript Internet
I love the "define:" tool on Google because:
  1. I am a bad speller
  2. It's nice to see a few different definitions
But I hate having to type define:" every time. So I wrote a very simple AppleScript to get around this:
set googleword to display dialog "What word do you want to define?" 
 default answer " "
set findgoogleword to (text returned of the googleword)
do shell script "open http://www.google.com/search?q=define:" 
 & findgoogleword
If you don't want to use Google, then all you have to do is change the address and modify the URL bit to match your preferred site's syntax.
    •    
  • Currently 1.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[11,520 views]  

Define words via Google and AppleScript | 20 comments | Create New Account
Click here to return to the 'Define words via Google and AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Define words via Google and AppleScript
Authored by: BulbVivid on Feb 16, '05 11:18:32AM

Cool dictionary script.

I submitted a similar hint some time ago (http://www.macosxhints.com/article.php?story=20031111202259919&query=clipboard+dictionary) that you may want to check out.

The script searches for whatever is in the clipboard using whatever URL you give it. Here it is using Google's define:

tell application "Safari"
activate

if not (exists document 1) then
make new document at the beginning of documents
end if

set page_info to the clipboard
set page_url to "http://www.google.com/search?q=define:" & page_info
set URL of document 1 to page_url

end tell

I use an iKey sequence for the copy command (cause I haven't had time/can't figure out/don't know if it's possible to applescript a global copy) and to run the script, to where all I have to do is highlight a word and hit a key command (or a mouse button) to copy it and look it up in my dictionary (I use the script to do Google searches the same way).

Though it's not quite as handy for looking up words not already typed (I use a bookmarklet in Safari for that, though I'll likely implement the parent hint for that now), it would be a nice supplement to the parent hint.

Jason



[ Reply to This | # ]
easier with Firefox
Authored by: sr105 on Feb 16, '05 11:20:40AM

I'll use Google for this example even though I prefer dictionary.com.
1. Lookup something.
http://www.google.com/search?hl=en&q=define%3Asomething
2. Bookmark this link. Firefox (by default) comes with a bookmark folder called "Quick Searches". Save the bookmark there for consistency.
3. Open "Manage Bookmarks..." under the "Bookmarks" menu
4. Find your new bookmark and edit its properties.
5. Change "something" in the url to "%s"
6. Add a keyword like "define" or "dict"
Done.

Go to the location box in the browser and type "define something". Firefox replaces the %s with whatever comes after the keyword.

There are other examples in that bookmark folder for stock quotes, etc.

I applaud the original author's desire to use applescript for this, but there was an easier way.



[ Reply to This | # ]
easier with Firefox
Authored by: BulbVivid on Feb 16, '05 12:21:35PM

Your suggestion, though viable, requires you to switch to your browser to look up the word. With an applescript, you can look up a word regardless of your frontmost application, even if your browser isn't open.

Though switching to the browser isn't a major step, if you look up words often, the convenience of the applescript is most welcome.

In Safari, you can use this javascript (change the name and URL to whatever you like): javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Merriam-Webster%20Dictionary%20search:',''))%7D;if(x!=null)window.location=window.location='http://unabridged.merriam-webster.com/cgi-bin/unabridged?book=dictionary&va='+x;

I'm sure similar javascripts are available for Firefox, though I haven't really looked.



[ Reply to This | # ]
easier with Firefox
Authored by: mark hunte on Feb 16, '05 12:56:29PM

In safari ( if you want to use a browser) you just have type in the google search box
define and your yourword/s. ie

define World Wide Web

and it will do a defined search. without the need to have bookmarks?


---
mh



[ Reply to This | # ]
easier with Firefox
Authored by: BulbVivid on Feb 16, '05 01:08:01PM

It's more about being able to select your dictionary if you have specific needs (say a medical dictionary or Spanish dictionary). I use Merriam-Webster's Unabridged subscription dictionary, so I can specify that in the various code examples in this thread (including the bookmarklet).

I rarely use the bookmarklet in Safari. I mostly use my highlight & lookup script, as it's the fastest way I've found to get a definition. The script in the parent of this thread is good for looking up a word you are thinking of, as opposed to one that is already typed or displayed.

The applescripts work best if they are bound to a keyboard command using Spark or some other app (I use iKey).



[ Reply to This | # ]
easier with Firefox
Authored by: sr105 on Feb 18, '05 10:57:46AM

Well, the original posted script was running using Safari so in either case, you'll be running a browser. I figured that most people usually keep their browser running in the background anyway. I have mine set to a blank start page for just this purpose: Cmd-Tab, Cmd-N, define word. I like the bookmarklet ideas, though. I may look into those further.

And in response to someone else's comment about just using the google field in the toolbar, I was actually trying to make others aware of firefox's bookmark substitution features. Also, there's no reason to even have a google field if you set a keyword of "g" or something short. Then, the location bar serves the same purpose and results in a cleaner interface.



[ Reply to This | # ]
easier with Firefox
Authored by: sr105 on Feb 18, '05 11:00:56AM

upon further review, the original applescript has merit for using whatever browser you have set as default and can be hot keyed. eh, whatever you prefer I suppose.



[ Reply to This | # ]
easier with Firefox
Authored by: BulbVivid on Feb 18, '05 01:24:59PM

I usually have my browser open and running, and yes, it's fairly easy to switch to the browser and use whatever way in the browser to look up a word.

However, if you look up a lot of words, any steps that can be removed only makes the process faster. I'm a book editor, and I keep my page layout open on one monitor, and my browser open on the other. Then I can just highlight a word, hit my mouse button to trigger the script (whether dictionary or Google search), and my browser displays the information. Two steps (highlight + mouse click) makes the process a lot easier. Not to mention that (using iKey) the script (the one I use anyway), is global. Any text that can be highlighted can be searched with a keystroke.

Also, the scripts allow you to specify your dictionary or search engine.

Your needs define what methods are best to use. For the occasional definition, the solutions offered by browsers are more than adequate. If you look up hundreds of words in a week, it's nice to have something that cuts out any extra steps that can be removed.

Jason



[ Reply to This | # ]
Define words via Google and AppleScript
Authored by: mag on Feb 16, '05 12:06:22PM

I'd personally skip totally the scripting bit and add a channel to AcidSearch instead. See AcidSearch here: http://www.pozytron.com/?acidsearch.



[ Reply to This | # ]
Define words via Google and Bash!
Authored by: TwoTimes on Feb 16, '05 01:49:28PM
Or, for those who want to launch it from the terminal, this is the script, to be saved as /usr/local/bin/googledefine:

#!/bin/bash
if [ ! $1 ]; then
   echo "Usage: googledefine word"
   echo
   exit
fi
open "http://www.google.com/search?q=define:"$1


[ Reply to This | # ]
Define words via Google and Bash!
Authored by: gwolosh on Feb 20, '05 11:14:48AM

If you're gonna launch it from the terminal, why not keep it in the terminal. Get lynx from somewhere, fink, darwinports, etc and your script becomes

#!/bin/bash
if [ ! $1 ]; then
echo "Usage: lookup <word>"
echo
exit
fi
/sw/bin/lynx -dump "http://www.google.com/search?q=define:$1" | more

(I changed the name of the script to lookup)

Gedaliah



[ Reply to This | # ]
Define words via Google and AppleScript
Authored by: Chris Biagini on Feb 16, '05 02:10:30PM
Better to avoid the do shell script bit if you can. This will run slightly faster:
open location 
	"http://www.google.com/search?q=define:" & findgoogleword


[ Reply to This | # ]
Define words via Google and AppleScript
Authored by: ob1cannoli on Feb 16, '05 04:31:47PM

Anyone wanna try and make a bookmarklet to do this? I'm not too knowing of javascript to get it done...but i'll try



[ Reply to This | # ]
Define words via Google and AppleScript
Authored by: ob1cannoli on Feb 16, '05 04:38:31PM
Actually...got it for myself! just add this to your bookmarks! javascript:window.location.href=("http://www.google.com/search?q=define:"+prompt("Word to define:","")) enjoy!

[ Reply to This | # ]
Define words via Google and AppleScript
Authored by: mark hunte on Feb 16, '05 06:46:16PM
I must admit thats very cool with the prompt. I changed mine to answers.com as it gives definitions, Thesaurus and more on one page.
javascript:window.location.href=("http://www.answers.com/"+prompt("Word to define:",""))
and also I now have
javascript:window.location.href=("http://www.google.com/search?hl=en&lr=&oi=defmore&q=define:"+prompt("Word o define:",""))

---
mh

[ Reply to This | # ]

Define words via Google and AppleScript
Authored by: vmann on Feb 16, '05 04:56:55PM

javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('What word do you want to define? ',''))};if(Qr)location.href='http://www.google.com/search?q=define:'+escape(Qr)+'⊂=Search'


[ Reply to This | # ]
M-W and Firefox
Authored by: BulbVivid on Feb 18, '05 04:57:08PM

Firefox users might want to check out this page: http://www.m-w.com/firefox/

Looks like Firefox is picking up a little steam.



[ Reply to This | # ]
Unix and Spaces
Authored by: BulbVivid on Feb 22, '05 10:14:07PM

When I run the script on anything with spaces (doing google searches for example), nothing happens. With a single word in the clipboard, everything's fine. Anyone know how to make the unix command work with spaces in the search string and the like (I have, well, no skills in this arena)?

Thanks



[ Reply to This | # ]
Unix and Spaces
Authored by: ReznorB5 on May 09, '06 08:54:49PM

Put quotes around the words you want it to look up. Everything between the quotes will be treated as one word.



[ Reply to This | # ]
Unix and Spaces
Authored by: ReznorB5 on May 09, '06 09:13:48PM

Oops. I forgot to escape the variable inside the script too...and I cannot remember how.



[ Reply to This | # ]