English Dictionary Lookup

Hi all,
I have a list of words, separated by line, that I want to look up with either Apple’s built in dictionary or an online one. So far I have been able to do the following:


-- Get the words into an array
set wordlist to every word of (do shell script "cat /Users/Alex/Desktop/wordlist")

repeat with i from 1 to the length of wordlist
	
end repeat

on get_definition(the_word)
	-- http://bbs.applescript.net/viewtopic.php?pid=39232
	try
		return do shell script "cURL " & (quoted form of ("dict://dict.org/d:" & the_word & ":*"))
	on error the_err
		return the_err
	end try
end get_definition

The problem is that get_definition returns a whole bunch of text that I don’t need, e.g.:

I only want the first or maybe second definition and that’s it. I then would want to put that back into a text file {tab delimited… } but I think I’ll be able to figure that out. I just don’t get how to clean up the output from dict.org, and I don’t know if maybe there’s an easier way to do this that uses only built in utilities.

Thank you in advance for any and all help, I truly appreciate it!

Hi Kadis,

If you don’t mind only using WordNet and only want one definition, Try this:

--  For example
set the_word to text returned of (display dialog "Enter Word" default answer "")

-- Do work
set theDef to get_definition(the_word)
-- Extract definition only
try
	set {TIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {return}}
	set theDef to (paragraphs 5 thru -4) of theDef as text
	set AppleScript's text item delimiters to TIDs
on error
	set theDef to "None found"
end try
-- Return definition
return theDef

on get_definition(the_word)
	try
		-- Note ":wn:1" (uses WordNet and collects one def. only)
		return do shell script "cURL " & (quoted form of ("dict://dict.org/d:" & the_word & ":wn:1"))
	on error the_err
		return the_err
	end try
end get_definition

Best wishes

John M

I sent you an email.
Let me know.