Hi,
I understand two things here. First of all our friend wants to know how many words are inside his document. Second of all, he seems to look for a dynamic solution (text variable) that would be automatically updated (otherwise no need for a variable).
So here is an approach. An idle task is continously updating a text variable. So our friend can have a dynamic count of the documents words. I chose to excluse etxt variables intances but it may require deeper adjustments (as some variables might not be to exclude).
I have used a snippet from @indiscripts tfor counting words : http://www.indiscripts.com/post/2011/09/what-exactly-is-a-word
#targetengine "session"
main();
//Will add a custom idleTask listener to count current document words
function main()
{
var myIdleTask = app.idleTasks.item("countWords");
if ( !myIdleTask.isValid ) {
myIdleTask = app.idleTasks.add({name:"countWords", sleep:100});
var onIdleEventListener = myIdleTask.addEventListener(IdleEvent.ON_IDLE, onIdleEventHandler, false);
}
}
//Idke task listener
function onIdleEventHandler(myIdleEvent)
{
var doc = app.properties.activeDocument,
tv;
if ( !doc ) return;
tv = doc.textVariables.item("countText");
!tv.isValid && tv = doc.textVariables.add({name:"countText", variableType:VariableTypes.CUSTOM_TEXT_TYPE});
tv.variableOptions.contents = String( countWords() );
}
//Snippet from indiscripts.com = http://www.indiscripts.com/post/2011/09/what-exactly-is-a-word
//with minor modification to exclude textVariable instances.
var countWords = function F(/*Story|Cell|Footnote*/every)
{
var ret, t;
every = every || app.activeDocument.stories.everyItem();
if( !every.isValid ) return 0;
ret = every.words.length - every.textVariableInstances.length;
t = every.texts &&
every.texts.everyItem &&
every.texts.everyItem();
if( !t ) return ret;
t.tables.length &&
ret += F( t.tables.everyItem().cells.everyItem() ) - t.tables.everyItem().cells.everyItem().textVariableInstances.length;
t.footnotes.length &&
ret += F( t.footnotes.everyItem() ) - t.footnotes.everyItem().textVariableInstances.length;
t = null;
return ret;
};
before anything is typed in…

Every time contents is added, counter is updated…

HTH,
Loic
Ozalto | Productivity Oriented - Loïc Aigon