Copy link to clipboard
Copied
Hi folks,
I've tried two different scripts (found on this site) to attempt to get the word count out of an entire book, including all stories, tables, and captions.
The first:
alert("There are "+ app.documents[0].stories.everyItem().words.length +" words in the active document.")
Then this one, which doesn't count numbers and symbols, which I like:
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "[\\u\\l][-\\u\\l]+";
found = app.documents[0].findGrep ();
alert ("There are " + found.length + " words in this document.")
The difficulty is that neither of them include words in tables. Is there a way to force this in this script?
Copy link to clipboard
Copied
// First do a word count in the main text (as before)
found = app.documents[0].findGrep ().length;
// Then find every word in every table in every story
t = app.documents[0].stories.everyItem().tables.everyItem().findGrep();
// "t" is an array of arrays, now you need to add the length of each array to "found"
for (i = 0; i < t.length; i++)
found += t.length;
alert ("There are " + found + " words in this document.")
Peter
Copy link to clipboard
Copied
As written, it threw an error. When I added script from one of my other ones, it did, but I am still not getting the correct answer. It now looks like this.
// First do a word count in the main text (as before)
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "[\\u\\l][-\\u\\l]+";
found = app.documents[0].findGrep ().length;
// Then find every word in every table in every story
t = app.documents[0].stories.everyItem().tables.everyItem().findGrep();
// "t" is an array of arrays, now you need to add the length of each array to "found"
for (i = 0; i < t.length; i++)
found += t.length;
alert ("There are " + found + " words in this document.")
It somehow manages to give a word count lower than the one which skips tables, and is over 1000 less than our "official" count from our translation company.
Copy link to clipboard
Copied
>It somehow manages to give a word count lower than the one which skips tables
That's bizarre. It doesn't do any subtractions, so how the total can be lower if you include tavles is beyond me.
>and is over 1000 less than our "official" count from our translation company.
What does "official count" mean?
Petr
Copy link to clipboard
Copied
It is strange. All I can guess is that there is somehow some hidden text in the document that the translation company's software is seeing. Is that a possibility with INDD files?
And it's a good question what "official" means. I'll have to ask our translation dept what the vendor is using to get that word count. I hope they haven't been shafting us all along...
Copy link to clipboard
Copied
Did you ever successfully find a way to count all of the words in a book, including captions, TOC, etc.? Is there a software now that does this? I can't even find TextCount.js.
I have inDesign CS3.
Thank you so much!
Copy link to clipboard
Copied
To me it seems that the premise in the OP is wrong. The GREP script does count words in tables.
Thanks,
Ariel
Copy link to clipboard
Copied
Hi,
You can try the following link for counting words including table:
http://indisnip.wordpress.com/2010/12/28/quicktip-counting-text-using-everyitem/
Regards
Peru.