Re: Word wordcounts
Re: Word wordcounts
- Subject: Re: Word wordcounts
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 25 Mar 2005 13:15:18 -0800
On 3/25/05 8:48 AM, "Imap McGrant" <email@hidden> wrote:
> tell application "Microsoft Word" to count of characters of active
> document
>
> and
>
> tell application "Microsoft Word" to count of words of active document
>
> give widely differing results than the Tools > Word Count... function
> in the GUI (off by about 50% in the second case for the document I have
> open right now). Unfortunately my clients will be expecting the count
> from the GUI for the most part, and it would look funny to say the
> least to bill them 50% more than the number they can easily see for
> themselves. Does anyone know how to get the statistics reported in the
> GUI wordcount function in AppleScript? (Not just to display it, which I
> suppose I could do via GUI scripting, but to assign the data to
> variables in the script.)
The 'compute statistics' command gives you the exact count of the UI's
Tools/Word Count:
tell application "Microsoft Word"
compute statistics active document statistic (statistic words)
end tell
--> 203 -- same as the UI Tools/Word Count
You can get the other numbers too, using the different enumerations of the
statistic parameter:
statistic words/statistic lines/statistic pages/statistic
characters/statistic paragraphs/statistic characters with spaces/statistic
east asian characters
And there's even an optional [include footnotes and endnotes boolean]
parameter if you need it.
------------------------
You wouldn't have got anywhere with GUI scripting - it doesn't work in Word.
You can approximate the UI total with AppleScript's own definition of
'word'. An earlier attempt I tried revealed a few discrepancies, and some
strange implementations of Word, too:
The Tools/Word Count feature seems to give a "common sense" definition of
words, whereas Word's AppleScript 'word' counts each punctuation mark,
carriage return, tab character, invisible character - everything except
spaces - as a 'word. Running this script:
tell application "Microsoft Word"
set l to {}
repeat with i from 1 to (count words of active document)
set end of l to content of word i of active document
end repeat
end tell
l
will show you what's included. (It seems the only way to do it, too: 'every
word of active document' results in just an 'every word of active document'
reference. 'content of every word of active document' results just in one
continuous text, not a list of words.)
AppleScript's own definition of 'word' is much closer to the UI Count:
Tools/Word Count
--> 203
tell application "Microsoft Word"
count (words of active document)
--> 292
set w to content of text object of active document
end tell
count words of w
--> 211
If you just get (words of w) you'll see what AppleScript considers words: it
omits all the punctuation, carriage returns, tabs, etc. The small
discrepancy between its 211 and the UI's 203 is probably accounted for by
the fact that (in my case here) AppleScript counts the "c" and "o" of "c/o"
as two separate words and the UI Count probably knows it's one "word", etc.
AppleScript misses the second half of phone numbers, mind you, after the
hyphen - odd.
But 'compute statistics' will get you exactly what you're looking for.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden