Drag the .js.txt file to Preferences / Toolbars / Scripts.
Add the Scripts > Word Count column to your file display.
You need to have Microsoft Word installed.
So far only tested with Word 2010.
Notes / Warnings:
The script talks to Microsoft Word to get statistics about the document. To do this, it has to ask Word to open the file, and then tells Word to close it when done.
As a result, if you have Word open, you may see its windows flicker as files are loaded and unloaded.
The script tries to detect if a document is already loaded into Word, and uses the existing open document if so, without closing it when done. There is a chance that detection won't always work, which might result in you being prompted to close the file you're editing (or having it close itself if there are no unsaved changes). If you notice anything strange happening within Word, close the Opus windows that have the column in them, and please report the problem here so the script might be improved.
You do not need the code below -- a copy of it is in the download, above -- but it is here for people browsing the forum looking for scripting techniques:
// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// Called by Directory Opus to initialize the script
initData.name = "Doc Word Count";
initData.desc = "Word count column for Microsoft Word documents. (Requires Microsoft Word.)";
initData.copyright = "(C) 2015 Leo Davidson";
initData.version = "1.0";
initData.default_enable = true;
var col = initData.AddColumn();
col.name = "DocWordCount";
col.method = "OnDocWordCount";
col.label = "Word Count";
col.justify = "left";
col.autogroup = true;
col.autorefresh = true;
col.type = "number";
var fsu = null;
var wordApp = null;
// Implement the DocWordCount column
var fileExt = scriptColData.item.ext;
if (scriptColData.col != "DocWordCount"
|| (fileExt != ".doc" && fileExt != ".docx")
|| scriptColData.item.name == "~")
if (fsu == null)
fsu = DOpus.FSUtil;
if (wordApp == null)
wordApp = GetObject("", "Word.Application");
wordApp = null;
if (wordApp == null)
wordApp = new ActiveXObject("Word.Application");
if (wordApp == null)
DOpus.Output("Failed to open Word", true);
// wordApp.Visible = true;
var wordDocuments = wordApp.Documents;
var filePath = scriptColData.item.realpath + "";
var wordFile = null;
var closeFile = false;
for(var docEnum = new Enumerator(wordDocuments); !docEnum.atEnd(); docEnum.moveNext())
var fullPath = docEnum.item().Path + "\\" + docEnum.item().Name;
if (fsu.ComparePath(fullPath, filePath))
DOpus.Output("File already loaded: " + fullPath);
wordFile = docEnum.item();
if (wordFile == null)
wordFile = wordDocuments.open(filePath, false, true, false);
closeFile = true;
DOpus.Output("Loaded: " + filePath);
if (wordFile != null)
scriptColData.value = wordFile.ReadabilityStatistics("words").Value;
Sorry I hadn't noticed this. Many thanks for the add-in, except I only get error messages, such as "ToolsGrammarStatisticsArray cannot be run on a document that contains more than one language format"
"Doc Word Count: Error at line 93, position 3
Doc Word Count: The requested member of the collection does not exist. (0x800a1735)
Doc Word Count: File already loaded: C:\Users\Olly\SkyDrive\Binnen\2015\juni\83689 Pokon BIO Groente en Kruiden pillen (origineel).docx
Doc Word Count: Error at line 93, position 3
Doc Word Count: The requested member of the collection does not exist. (0x800a1735)"
I'm not an MS Word expert but from the first error message I guess that Word won't provide statistics (even simple word counts) from mixed-language documents. I don't know if there is any way around that problem for such documents.
The "file already loaded" lines can be ignored. That was just a diagnostic message which I think I forgot to remove from the script, but is harmless.
I had to disable the add-in because all docs were now opening in "compatibility mode" (i.e. non-editable), wherever I opened them from. Could this be why I wasn't getting word counts? The word count in Word itself has no problem with more than one language format...
Not unless there's a way for Word to load .md files. (Maybe there is?) Although a basic text word count (treating the markup as normal words) would probably be quite close to correct for typical markdown text, I think?