InDesign Check Spelling without launching Spell Check?

Is there any way to have InDesign check spelling via a script and list any misspelled words via the script? Similarly, if there were no found spelling errors, then the script could return a prompt, i.e., “No Spelling Issues Found”.

You might ask why?

I have created a somewhat robust preflight-like script that checks for common issues specific to our guidelines, e.g., low resolution files, modified links, objects set to 100% black, overset text frames, etc.

It was suggested that it would be nice to have this also execute a spell check, without having to leave the script and launch InDesign’s spell check. But I could not find any method to do so.

If it’s not possible, that’s fine too. I could have the script ask, “Would you like to check Spelling and then run this script again.” buttons {“Yes”, “No”}.

But ideally, I would like to incorporate the spell check into the script so that it would never have to leave the script and then could jump to the next routine that does other quality checks.

Just curious if there is such a way?

Thanks,
-Jeff

I don’t think there’s a way in InDesign. However, you could extract the stories and check them using the system spelling checker:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

my dodgyWordsIn:"Is there any way to have InDesign check spelling via a script and list any misspelled words via the script? Similarly, if there were no found speling errors, then the script could return a prompt, i.e., \"No Spelling Issues Found\"."

on dodgyWordsIn:theString
	set anNSString to current application's NSMutableString's stringWithString:theString
	set theChecker to current application's NSSpellChecker's sharedSpellChecker()
	theChecker's setLanguage:"en_AU" -- optional
	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)
	set susWords to {}
	repeat with aFind in theProblems
		set end of susWords to (anNSString's substringWithRange:(aFind's range())) as text
	end repeat
	return susWords
end dodgyWordsIn:

Wow! Thank you very much once again Shane, this might actually do the trick!

-Jeff

Hi Shane, is there a way to incorporate a different dictionary that closely replicates what InDesign is using, e.g., Hunspell. For example, the word Doylestown and the web address Zadalbashamediterraneangrill.com in the code snippet below would be flagged by InDesign, which is what I am aiming for.

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

my dodgyWordsIn:"Is there any way to have InDesign check spelling similar to what it flags for words such as, Doylestown, or even a web address like, Zadalbashamediterraneangrill.com \"No Spelling Issues Found\"."

on dodgyWordsIn:theString
	set anNSString to current application's NSMutableString's stringWithString:theString
	set theChecker to current application's NSSpellChecker's sharedSpellChecker()
	theChecker's setLanguage:"en_AU" -- optional
	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)
	set susWords to {}
	repeat with aFind in theProblems
		set end of susWords to (anNSString's substringWithRange:(aFind's range())) as text
	end repeat
	return susWords
end dodgyWordsIn:

What do you mean by “closely replicates”?

You can just set the desired dictionary (spelling vendor):



You can also set a custom dictionary path. I personally don’t have much experience with these options though.

p.s. also language’s spelling vendor:

for example:

tell document 1
		spelling vendor of language 1
end tell

Hi leo_r,
In this instnce, I am trying to avoid using InDesign’s spell check mechanism altogether. The script in this post utilizes the system spelling checker.

I wouldn’t need to seek an alternative spelling mechanism if there were a way to determine when InDesign’s “Check Spelling” window has closed. Since there isn’t, I was considering checking for any misspelled words and displaying an alert when necessary, such as: “Found the following misspelled words: ‘speling’, ‘reciept’, ‘seperat’. You should run InDesign’s spell check.”

The issue with the system spelling checker is that it doesn’t seem to catch as many misspellings as InDesign does.

Ah ok I see. I didn’t evaluate the script in depth.

Just a shot in the dark: you can check some 3rd-party tools like Grammarly; maybe they have APIs to check text, which can also be invoked from AppleScript.

No, you can’t I’m afraid.

You could use the InDesign Preflight function for that.
Go to Window → Output → Preflight to open the panel.
Make a new profile. You will find numerous options that fit your needs.
Particularly, the one that checks if your document has spelling issues.
(Can’t tell you the exact name as my indy is in French)

1 Like

Thank you, ionah. I completely forgot about the Preflight functionality.