Copy link to clipboard
Copied
How do I delete all words added to the “All languages” language in the User Dictionary dialog that were merged into the Document with a script?
According to this post such words are stored as hyphenation exceptions and therefore accessible with scripting via app.activeDocument.hyphenationExceptions, but words added to the “All languages” language seems to be the exception. This code displays (in the console) all languages and the number of hyphenation exceptions for each language:
var myHyphenations = app.activeDocument.hyphenationExceptions;
var myHyphenationsLength = myHyphenations.length;
for (var i = 0; i < myHyphenationsLength; i++ ) {
myHyphenation = myHyphenations[i];
var myAddedWords = myHyphenation.addedExceptions;
$.write(myHyphenation.name + ": " + myAddedWords.length + "\n");
// myHyphenation.removeException(myAddedWords);
}
which matches what is seen in menu Edit ▸ Spelling ▸ User dictionary ▸ Target: [current doc] for each language listed in the Language drop down menu, except for the “All languages” language. The code above does not account for entries in that language at all, nor lists category even. Are those accessible via scripting at all?
Copy link to clipboard
Copied
I don't know about this - I don't think there is scripting support for document-specific user dictionaries in InDesign. The scripting capabilities seemingly focus on the application-level dictionary, and accessing the "All languages" language in the User Dictionary dialog specifically is not supported through scripting.
The code you provided is for removing hyphenation exceptions, which are different from the user dictionary words.
But maybe @m1b (sorry can't remember the handle for other scripters) knows how to access this.
Copy link to clipboard
Copied
I don't think there is scripting support for document-specific user dictionaries in InDesign. […]
The code you provided is for removing hyphenation exceptions, which are different from the user dictionary words.
That is not correct. Hyphenation exceptions are but words with hyphenation hints that are stored in a user dictionary:
Deleting words from the documents’ user dictionary via scripting (irrespective of them having or not having hyphenation hints) is what the line commented out at the end of the for loop does, only that it seemingly affects words added to all languages except the “All languages” language.
So the key to my question is whether there is indeed no scripting support only for words added to “All languages”.
Copy link to clipboard
Copied
Ah I see - thanks for clarifying!
Copy link to clipboard
Copied
Peeking into an unzipped IMDL, the language of the hyphenation exceptions added to “All Languages” seems to be named “Neutral”:
<HyphenationException … Name="$ID/Neutral"
even though no such HyphenationException is listed when asking for the names of all HyphenationExceptions as in the code above, not when requesting specifically:
app.activeDocument.hyphenationExceptions.itemByName("Neutral")
which is invalid.
I suspect that the seemingly lack of scripting support for that “Neutral” language’s user dictionary might have related the bug reported in this thread by which hyphenationExceptions.itemByName() returns the wrong hyphen..., particularly the one intended +1 as per the collection’s index. I wonder if the +1 is due to “Normal” not being accounted for in some part of the code but not others.