Copy link to clipboard
Copied
As you friends, my question is about the Indesign User Dictionary.
I wonder if there is any way through a script, to compare if a certain word already exists within the list of User Dictionary.
Thanks for the help of your friends.
Copy link to clipboard
Copied
InDesign's dictionaries have limited scripting possibilities, you'll struggle to get much useful scripting mileage out of it.
But why would you want to know whether a word is in the dictionary? If you think a word should be there, just add it: InDesign doesn't store a word twice.
Copy link to clipboard
Copied
Hi Peter, thanks for the attention my friend.
I@ have a script what return a list with every misspelled words in document, some of these words are from other languages like English and Spanish, I would like to find a way to check if those words are already in the Indesign dictionary and then change the language in those words so they do not appear again in the list of misspelled words.
Copy link to clipboard
Copied
I think I'm beginning to understand. You have a Portuguese text that can contain some English and/or Spanish words. The basic language is Portuguese, and those English and Portuguese words are flagged as misspelled. And you want to check whether those misspelled words exist in the English or Portuguese dictionaries and if they do, apply a character style that sets the language for those words so that they are no longer flagged as misspelled.
If that's a correct summary, then the answer is no, you don't have access to InDesign's dictionaries. User dictionary, yes: you can export it to a text file, but you want the main dictionary.
You say you have a script that returns misspelled words. I'd be interested to see that.
Copy link to clipboard
Copied
Thanks for the response Peter, even though it's not the one we'd like to receive, let's hope Adobe someday provides something of the kind we were looking for in relation to dictionaries.
About the script that you're interested in, I'm putting it here.
This script was built with the help of friends here from the Forum and friends here from the company.
I ask for help to know if it would be possible through this script, to change the language of the words found to English so that these words do not appear in the final list?
Did we get through this script to come up with a solution next to what we were looking for?
Thank you very much for the attention my friend. Greetings from your Brazilian friend.
#target indesign
var myDoc = app.activeDocument;
var mySpellPref = app.spellPreferences;
myDoc.save(File(String(myDoc.fullName)));
//uncheck preferences of verify spellprof
mySpellPref.checkCapitalizedSentences = false;
mySpellPref.checkCapitalizedWords = false;
mySpellPref.checkRepeatedWords = false;
mySpellPref.checkMisspelledWords = true;
//add character style phantom
myDoc.characterStyles.add({name:"palavra"});
//invoke verify spellprof
var myMenu = app.menuActions.item('Verificar ortografia...');
var resultado;
for(var i = 1; i <= 1000; i++){
myMenu.invoke();
app.selection[0].appliedCharacterStyle = "palavra";
//insert break
if(i==1){
resultado=app.selection[0];
}else if(resultado===app.selection[0]){
break;
}
}
//check preferences of verify spellprof
mySpellPref.checkCapitalizedSentences = true; //Frases sem maiúsculas
mySpellPref.checkCapitalizedWords = true; //Palavras sem maiúsculas
mySpellPref.checkRepeatedWords = true; //Palavras repetidas
var list = [];
// Clear find and change Grep
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedCharacterStyle = myDoc.characterStyles.itemByName("palavra");
var found = myDoc.findGrep();
// Clear find and change Grep
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Add array
for (var i=0; i<found.length; i++) {
list.push(found.contents);
}
//removing repeated words
function unique(list) {
var o = {}, i, l = list.length, r = [];
for(i=0; i<l;i++) o[list] = list;
for(i in o) r.push(o);
return r;
};
//Create list
var listFinal = unique(list).join("\r");
//remove character style phantom
myDoc.characterStyles.item("palavra").remove();
//Saving list
var myFile = new File(String(app.activeDocument.fullName).replace(/\.indd$/i, ".txt"));
if (File.fs == "Windows")
var listFile = myFile.saveDlg("Save list", "Plain text file: *.txt" );
else
listFile = myFile.saveDlg("Save list");
if (listFile != null) {
if (listFile.open("w")) {
listFile.encoding = "utf8";
listFile.write(listFinal + "\r");
listFile.close();
listFile.execute();
}
}
//Open folder
var folder = Folder(myDoc.filePath);
folder.execute();
//close document without saving for dont preserve changes
myDoc.close(SaveOptions.no);
Copy link to clipboard
Copied
Thanks for that script. Interesting.
What you're after could be done, in fact. It's a really awful way of going about things, but in principle it's possible. It's messy and slow, but should work:
1. Your script produces a list of words which may be misspelled, Spanish, or English (or a combination of all!)
2. The script then creates a new document and places that list in a text frame. Apply Spanish. The script checks the content of that frame. Get the words not in the character style: they are are spelled correctly in Spanish. Split the list in two: those not in a character style (the correct Spanish words) and the words in the character style, which are misspelled in Portuguese and Spanish. Discard the document.
3. The script then creates a new document and places the remaining misspelled words in a text frame. Apply English. The script checks the content of that frame. Split the list in two: words in the character style are misspelled in English, words not in the character style are correct in English. Discard the document.
4. You now have three lists: correct Spanish, correct English, and misspelled. Apply Spanish (or a character style) to the Spanish words, English to the English words, and a third character style to the remaining words, which are either misspelled or do not occur in the English or Spanish dictionaries.
Not pretty, but should work.
P.
Copy link to clipboard
Copied
Hello Peter, let's do some testing with your suggestions.
I am very happy with this exchange of knowledge that we are having.
Thank you my friend.
Soon I will come back with some response regarding whether it worked or not.