Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pcLoadLetter

macrumors newbie
Original poster
Mar 23, 2017
2
0
I have the following spell checker script in AppleScript Objective C that is only catching some of the misspelled words. For instance, it seems to think the word "defnece" is spelled correctly. It also doesn't catch French or Spanish words even thought the language is set to English. Any ideas what needs to change? I'm on Mac OS High Sierra.


------------------------------------------------------------------------------------------------------

--ADDING WORDS TO THE SPELL CHECKING DICTIONARY

------------------------------------------------------------------------------------------------------


--Creating a list of ok words to not spell check

--Vendor names would go here

set ok_words to {"Absorbine", "Adams", "Addie", "Advantix", "Agratronix", "Agrimaster", "Alfred", "Algoma", "Ameristep", "Andis", "Ardisam", "Armorall", "Armour", "Aruba", "Attwood", "Avalon", "Avantect", "Baraboo", "Barronett", "Benjamin", "Belcaro", "Behlen", "Berkley", "Blackstone", "Boehringer", "Boone", "Bostitch", "Bovikalc", "Buddeez", "California", "Camco", "Canidae", "Carhartt", "Carbor", "Carlisle", "Cathy", "Caviness", "cg/cg®", "Chippewa", "Citgo", "Columbia", "Contico", "Crayola", "Daiwa", "Danby", "Daniels", "Dasco", "Dayco", "Deere", "Delco", "Delonghi", "De’longhi", "Delvac", "Delmont", "Deroma", "Dewalt", "Dogzilla", "Doorbusters", "Doritos", "Doskocil", "Doug", "Delavan", "Dramm", "Drive-Maxx", "Drylok", "Dupont", "Durabilt", "Duracraft", "Durafork", "Durvet", "Eco-Flo", "Ecolution", "Edsal", "Enoz", "Eppinger", "Eprinex", "Erika", "Ertl", "Esoterra", "Estwing", "equaline", "Equimax", "Eukanuba", "Farnam", "Farberware", "Fats Tackle", "Fats Tackle ", "Fimco", "Fiora", "Firstect", "Fiskars", "Flexbrew", "Flotec", "Flueriares", "Folgers", "Flexzilla", "Freshtech", "Friskies", "Frogg", "Gabriel", "Generac", "Geneseo", "Genflex", "Geotek", "Giftables", "Gilmour", "Gojo", "Graco", "Greenleaf", "Grubex", "Gumout", "Hackzall", "Hamilton", "Harvestpro", "Havahart", "Heinz", "Herculiner", "Hershey's", "Hobart", "Holmes", "Homeright", "Homz", "Honda", "Hornady", "Husqvarna", "Hypro", "Iams", "Ingelheim", "Intex", "Invizx", "Irwin", "iXtreme", "Jakks", "Jobes", "Kaboodle", "Kärcher", "Karcher", "Kawasaki", "Kaytee", "Kilz", "KitchenAid", "Klean-Strip", "Kote", "Krups", "Kurgo", "Larin", "Leviton", "Lews", "Lincoln", "Livingston", "Lucas", "Lund", "Lunex", "Marklyn", "Masterbuilt", "Maxx", "Mccloskey", "Mcsunley", "Meguiar’s", "Meguiar's", "Melissa", "Merial", "Merrick", "Michelin", "Milorganite", "Milwaukee", "Minnkota", "Minwax", "Miracle-Gro", "Monroe", "Moonrays", "Morton", "Motorcraft", "Muckster", "Multifloor", "Munsing", "Mystik", "Naptha", "Nesco", "Neverkink", "Nexave", "Norpro", "Nutrena", "Nutrish", "Nyjer", "Nylabone", "Odessa", "Oespectrum", "Oil", "Okeechobee", "O’keeffe’s", "O'keeffe's", "Okuma", "Oxy-Acetylene", "Peg-Pérego", "Petlodge", "Permatex", "Petsafe", "Pflueger", "Philips", "Piranhamax", "Pradco", "Proheat", "Progrip", "Proplan", "Prozap", "Purolator", "Rachael", "Rapala", "Rayovac", "Realtree", "Reebok", "Reese", "Remington", "Rinehart", "Roebic", "Rotella", "Sakrete", "Sandusky", "Sawzall", "Scalibor", "Scotts", "Seaguar", "Seaquest", "Seasense", "Sellars", "Seresto", "Seymour", "Shademaker", "Sheba", "Shelterlogic", "Shimano", "Shur", "Shur-tred", "Shur-Line", "Skechers", "Sonicare", "Sorel", "Speeco", "Spiderwire", "Standlee", "Stax", "Stearns", "Stihl", "Stik", "Stratton", "Sperry", "Sturtevant", "Suncast", "Sundolphin", "Sunfilm", "Sunjoy", "Sweepfire", "Swiffer", "Swiveleze", "Tannerite", "Teske", "T-Fal", "Thermacell", "Thompson", "Toggs", "Tonka", "Toughmax", "Tricam", "Trico", "Trilene", "Trimec", "Troy-Bilt", "Trufuel", "Truper", "Twizzlers", "Ultra-Maxx", "Uquality", "Valvoline", "Vanderbilt", "Varathane", "Ventamatic", "Vetality", "Wahl", "Weatherbeater", "Weatherguard", "Werner", "Wyoming", "Zareba", "Zecol", "ZeroXposur", "Zimecterin", "Zinsser", "Zuke's"}


------------------------------------------------------------------------------------------------------

--ENABLING SCRIPTING ADDITIONS

------------------------------------------------------------------------------------------------------


--Enabling scripting additions

--This is necessary because the spell check doesn't work without enabling additions

use AppleScript version "2.4"

use scripting additions

use framework "Foundation"

use framework "AppKit"



------------------------------------------------------------------------------------------------------

--CHECKING SPELLING

------------------------------------------------------------------------------------------------------


tell application "Adobe InDesign CC 2018"

activate

set user interaction level of script preferences to interact with all



set potential_prob_words to {}

tell active document to set my_stories to every story

set the_doc to active document

repeat with my_story in my_stories

tell the_doc to set parent_text_frame to (every text frame whose contents contains (contents of my_story))

set my_words to every word of my_story

set word_count to count my_words



set current_count to 1

repeat word_count times

set my_word to word current_count of my_story



--Running the check_spelling function towards the bottom of the script

set misspelled_word to (my check_spelling(my_word, ok_words))



--Selecting the potentially misspelled word

if misspelled_word is not {} then

select parent_text_frame

select word current_count of my_story

set potential_prob_words to potential_prob_words & misspelled_word





------------------------------------------------------------------------------------------------------

--DISPLAYING THE SPELL CHECK DIALOG

------------------------------------------------------------------------------------------------------



--Creating the dialog

set my_field_width to 200

set dialog_name to "CHECK SPELLING FOR WORD " & misspelled_word as string

set myDialog to make dialog with properties {name:dialog_name}

tell myDialog

set can cancel to false

tell (make dialog column)



--Creating the page size fields

tell (make dialog row)

make static text with properties {static label:"Enter the correct spelling (or hit enter, if word is ok):"}

end tell

tell (make dialog row)

make static text with properties {static label: (misspelled_word as string)}

set respell_field to make text editbox with properties {edit contents: (misspelled_word as string), min width:my_field_width}

end tell

end tell

end tell



--Getting the respelled word

if (show myDialog) = true then

set respelled_word to edit contents of respell_field

end if



--Making the dialog go away

destroy myDialog



--Replacing the problem word with the respelled word

if misspelled_word as string is not respelled_word as string then

my find_replace((misspelled_word as string), respelled_word)

end if



end if



set current_count to current_count + 1

end repeat

end repeat





------------------------------------------------------------------------------------------------------

--DISPLAYING THE FINISHED DIALOG

------------------------------------------------------------------------------------------------------



if potential_prob_words is not {} then

display dialog "SPELL CHECK COMPLETE" & return & "Spell check is done checking the page(s)" with icon 1 giving up after 5400

else

display dialog "HALLELUIAH!" & return & "No misspelled words found" with icon 1 giving up after 5400

end if



end tell



------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------

--FUNCTIONS

------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------


--FUNCTION NEEDED TO CHECK SPELLING

on check_spelling(theString, current_dictionary)

set anNSString to (current application's NSMutableString's stringWithString:theString)

set theChecker to current application's NSSpellChecker's sharedSpellChecker()

theChecker's setLanguage:"en" -- optional

--tell theChecker to unlearnWord:"defnece")



set theProblems to (theChecker's checkString:anNSString range:{0, anNSString's |length|()} types:current application's NSTextCheckingTypeSpelling) options: (missing value) inSpellDocumentWithTag:0 orthography: (missing value) wordCount: (missing value))



--Creating blank lists to add misspelled words not in dictionary

set susWords to {}



repeat with aFind in theProblems

set potential_prob to (anNSString's substringWithRange: (aFind's range())) as text



--Adding problem words to the problem word list IF the problem word is not in the ok list

--and the problem word doesn't contain Reg. etc.

if potential_prob as string is not in current_dictionary then -->excluding all words in the ok list (like brand names)

set temp_list to {} -->beginning of excluding measurements code (excluding things like 11x12x24 to keep measurements out of spell check)

if potential_prob & return as string is not in current_dictionary then -->excluding the word if it's in the ok list but has a return after it

set susWords to susWords & (potential_prob as string) -->adding all potential misspellings to a list

end if

end if

end repeat

return susWords

end check_spelling


-------------------------------------------------------------

-------------------------------------------------------------



--FUNCTION TO REPLACE TEXT

on find_replace(search_term, replace_term)


tell application "Adobe InDesign CC 2018"

set find text preferences to nothing

set change text preferences to nothing



set find what of find text preferences to search_term

set change to of change text preferences to replace_term

--set color swatch of change text preferences to "C=0 M=100 Y=0 K=0"

--set applied character style of change text preferences to "Website Footer"

tell selection to change text

--change text document 1



set find text preferences to nothing

set change text preferences to nothing

end tell

end find_replace
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.