get red-dot-underlined words from Applespell

Can I check via applescript if a word is not in my default Language Dictionary?

i.e get a word that will be red-dot-underlined in say TextEdit because it is NOT in British English Dictionary (my selected language) OR in my User dictionary (my learned words)?

Reason I ask is because I’m writing a utility that will import a text doc & automatically add all red-underlined words into the User dictionary. Naturally I can read & write to the User dictionary file (in ~/Library/Spelling), but where is Applespell’s British English dictionary, & can I access it in plain text?

To clarify, it’ll be something like this…

set BritishEnglishDictionaryWords to {"some", "random", "and", "many", "more"}
set myCustomDictionary to {"innit"}

set myText to "Some random malarky, innit!"

set myTextWords to words of myText
set UnknownWords to {}
repeat with i from 1 to count of myTextWords
	if (item i of myTextWords is not in BritishEnglishDictionaryWords) and (item i of myTextWords is not in myCustomDictionary) then
		set UnknownWords to UnknownWords & (item i of myTextWords)
	end if
end repeat

get UnknownWords

just need to generate BritishEnglishDictionaryWords…?

Hopefully helpful. I don’t know if websters is American English or British English. Nor have I checked for specific versions at the path below, maybe you are in luck. And I’m not confident that text-edit uses Websters directly, I just hope there is something there you can use; at least that Websters contain the British spelling of your variant (not invariant) words.

You can play a little with the line below to find it either working, or not working for you, (and have a look inside that dict folder).

set searchresult to (do shell script "grep " & searchWord & " /usr/share/dict/web2 ")

Webster’s is definitely not British English! :lol: It’s historically responsible for American spellings and thus for many of the wince-inducing things we have to write in computer scripts and ” er ” programs.

Perhaps if the English hadn’t added the -me in the 19th century in an attempt to appear more French, you wouldn’t find it so annoying :wink:

Hi all

May you let French out of your dispute about English from Great Britain and English from the USA.

We have a sufficiently long list of disputes, no need to add a new one :wink:

KOENIG Yvan (VALLAURIS, France) samedi 10 août 2013 17:11:05

@McUsrII
Thanks, this is useful. Though it’s US-english, better than nothing.

I suspect the system uses Oxford Dictionary of (British) English, as per Dictionary.app… which is ©, so probably encrypted???

There’s a note in that directory…

“Dictionaries for other languages, e.g. Afrikaans, American, Aussie,
Chinese, Croatian, Czech, Danish, Dutch, Esperanto, Finnish, French,
German, Hindi, Hungarian, Italian, Japanese, Latin, Norwegian, Polish,
Russian, Spanish, Swahili, Swedish, Yiddish, are available
at ftp://ftp.ox.ac.uk/pub/wordlists.

…but I can’t get on to the server. As far as I can tell these are strictly for hackers who want to take over NASA or something.

WRT Language disputes:

so peace & brotherly love to all.

Hmmm… it’s working close enough to use Webber’s Dictionary.

I’ve got this:

--LOOK UP IN WEBBER'S DICTIONARY
on LookUpInWebbers(someword)
	try
		set searchresult to (do shell script "grep " & someword & " /usr/share/dict/web2 ")
	on error
		set searchresult to ""
	end try
	set searchresultWords to words of searchresult
	if someword is in searchresultWords then
		return true
	else
		return false
	end if
end LookUpInWebbers

The problems is that Webber’s dictionary doesn’t include plurals of nouns!!!
So it matches “pie” but not “pies”

set importData to "Groober's pies taste... minging!"

set importData_words to words of importData
set UnknownWords to {}
repeat with i from 1 to count of importData_words
	if my LookUpInWebbers(item i of importData_words) is false then
		set UnknownWords to UnknownWords & (item i of importData_words)
	end if
end repeat

get UnknownWords

The above wants to add {“Groober’s”, “pies”, “minging”}
(“minging” is already in the User dictionary, so will be dealt with later.)

I can try testing for words ending in s stripped of the s:

--LOOK UP IN WEBBER'S DICTIONARY
on LookUpInWebbers(someword)
	try
		set searchresult to (do shell script "grep " & someword & " /usr/share/dict/web2 ")
	on error
		set searchresult to ""
	end try
	set searchresultWords to words of searchresult
	if someword is in searchresultWords then
		return true
	else
		
		--maybe plural?
		if character (count of someword) of someword is "s" then --word ends in "s"...
			--...so see if word stripped of "s" is in dictionary
			set someword_singlular to text 1 thru ((count of someword) - 1) of someword
			try
				set searchresult to (do shell script "grep " & someword_singlular & " /usr/share/dict/web2 ")
			on error
				set searchresult to ""
			end try
			set searchresultWords to words of searchresult
			if someword_singlular is in searchresultWords then
				return true
			else
				return false
			end if
			
		else
			return false
		end if
	end if
end LookUpInWebbers

…but this is cumbersome, & it’s bound to misfire on some words. (Mouses?)

Any suggestions?