You need to query Word for the count of document
objects – active document
is just a convenience shortcut to the frontmost one in that list. Unluckily, Word’s somewhat peculiar AppleScript implementation does not return an empty list object when there is no open document, but missing value
(AppleScript’s take on nil
) instead. Taking that into account, the following function queries Word for open documents:
on hasDocument()
tell application "Microsoft Word"
every document is not missing value
end tell
end
– put that in front of your script and change your conditional to if it is running and my hasDocument()
and you should be fine.
Update: I originally had this using a Table. But have now changed it to a Text Object.
Here is you start then.
Save this Applescript as a Stay Open Application.
on idle
tell application "Pages"
set ActualCount to count words of body text of document 1
set calculation to ActualCount * 0.02
set object text of text item 1 of document 1 to (ActualCount & " words = £" & calculation as string)
end tell
return 5 -- runs every n# seconds
end idle
Now in your document add a Text Object.
In the Text Object Arrange tab in the Format inspector.
Set the Object Placement to Move with text.
And *Text Wrap to Above and Below
This will save the need to manually move the Text Object down the document as you go.
Now run the App. Start typing.
The one thing you will notice is that the real word count sees the word in the table. 329 That is why I have included the word count in the text objects results. 326 words = £6.5
Best Answer
Yes. You could use this:
Since you asked for the word count of "the currently open Microsoft Word® document" this does it. This script works ONLY in the case where you have a single Word document open.
It works for Word 2011 and for Word 16.25 (from Office 365).