Copy link to clipboard
Copied
I have a lengthy InDesign document and would love to get a word count of all the text on a page-level basis (i.e., page 1 has 156 words, page 2 has 190 words, etc.). I'm using AppleScript.
The text is all in one story, so getting it by story doesn't help me. Each page begins with an occurence of a paragraph style I have called "Title."
Thanks for any help you are able to give!
Hi Randolph_McMann,
Try this code:
Copy link to clipboard
Copied
Hi Randolph_McMann,
Try this code:
Best
Sunil
Copy link to clipboard
Copied
Sunil,
You're a genius. That seems to do just what I needed it to do. Thank you so much.
(I would have responded sooner, but I did not get an email saying my post had been replied to, even though I clicked that option.)
Randolph McMann
Copy link to clipboard
Copied
Hi Randolph,
below some ExtendScript (JavaScript) code for all using InDesign on Windows and/or on Mac OS X.
Run this code snippet when text is selected in the story. Could be a single insertion point as well.
/*
WARNING:
1. NOT COUNTING words in table cells, words in footnote texts.
2. Not counting words if the text frame or the text path is on the pasteboard.
Also see what exactly makes a word here:
Highly recommended read, blog post by Marc Autret:
http://www.indiscripts.com/post/2011/09/what-exactly-is-a-word
*/
// SELECT SOME TEXT BEFORE RUNNING THIS:
var story = app.selection[0].parentStory;
var textContainers = story.textContainers;
var resultArray = [];
var resultString = "PagePos" +"\t"+ "Number of Words";
for( var n=0; n<textContainers.length; n++ )
{
if( textContainers[n].parentPage == null ){ continue };
var pagePositionString = ( textContainers[n].parentPage.documentOffset + 1 ) + "" ;
if( resultArray[pagePositionString] == null )
{ resultArray[pagePositionString] = textContainers[n].words.length }
else
{
resultArray[pagePositionString] =
resultArray[pagePositionString] + textContainers[n].words.length;
};
};
for( x in resultArray )
{
resultString = resultString +"\r"+ x +"\t"+resultArray[x] ;
};
alert( resultString );
Below a sample result where a story is threaded from page 1 to the pasteboard, then on to page 2, page 4 and back to page 1 of a document. The text on the pasteboard will not be counted.
Another note: To get word count with table cells and footnote text as well one could use e.g. GREP Find and limit the scope to text frames and text paths of a story. FWIW: The code above will also count text in frames that are nested inside e.g. groups.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thanks, Uwe! I hope my question has helped others. Thanks to your response and Sunil's, all the programming bases are covered.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more