An easy* way to display the word count of your writing projects live on stream.
* For given values of "easy."
See it in action on Youtube.
Have you ever been writing a book, and wanted to show your live word count on stream in a big fancy way? No? I'm the only one?
That figures.
Well regardless, this sure is one way to do it.
- Count the words in your the most recently-edited markdown file in your book's folder live, and write that number to a file every time it changes.
- Count ALL the words in all the markdown files in your book's folder, write the number to a file, etc.
- The script can also capture and log the name of the current file you're working on as well as what sub-folder it happens to be in, if any.
- All this data gets written to separate text files, which can then be used as text sources in OBS.
- Some familiarity with the command line.
- Linux
- You could probably get this to work on Windows via WSL, but I won't be testing that any time soon.
- A folder full of: markdown files, subfolders full of Markdown files, or both.
- Yes, this was specifically designed for use with Markdown.
- I'm using Obsidian as my editor, but any text editor will do, especially if it auto saves.
- A desire to actually be this goddamned nerdy.
Note: A previous version of this script made use of the markdown-word-count Python package as a dependency. I have replaced it with a simple sed command that strips everything that doesn't look like a word for simplicity.
Warning: This script will count words in a file's front matter, but the mwc package had the same issue, so no change there. However, this new version of the script will also count words in code blocks, at present.
Alright, so get your dependencies in order first. All of this script is comprised of plain old Bash and GNU utilities. It should be compatible with most Linux distros, and even WSL.
Also, this whole guide was written in like an hour after spending most of my day working on the script. It may need revising later.
Either clone this repository, or just download the files zipped. Grab wordcount and wordwatcher because you'll need both.
You can do the following in any order, really:
Run chmod +x wordcount and chmod +x wordwatcher, or use the Properties dialogue in your favorite file browser to mark them as executable.
This is so you can run the scripts from anywhere by just typing wordwatcher /your/book/folder/here.
I accomplish this by having a dedicated folder for my own scripts in my home folder. So, if your home folder is located at /home/yourusername/, you could create a folder called scripts in your home folder, and put the two files you downloaded in there.
Then, open your .bashrc file (located at /home/yourusername/.bashrc) and add this... pretty much wherever you like, though I prefer to have it at the bottom:
PATH=$PATH:$HOME/scripts
Then run source $HOME/.bashrc in your terminal to update the configuration, so typing wordwatcher will run the script.
So first, you need to make a folder called streaming in your home folder, e.g. /home/yourusername/streaming. When you run the scripts, the text files that you'll be using for the stream will be created in that folder.
Then you need to prep your book folder. If you're writing your book in Markdown like I am, you're probably way ahead of me. If you're not, here's the deal: these scripts were designed to be used inside a folder full of markdown files. Now, it could just be a folder and chapter files, like so:
Yourbook
- Chapter 1.md
- Chapter 2.md
- etc.md
Or you can use subfolders like this:
Yourbook
- Chapter 1
- Scene 1.md
- Scene 2.md
- Chapter 2
- Scene 3.md
- Scene 4.md
Once you have everything organized, you're ready to start.
Warning: If you use sub-sub folders with markdown files inside of those, this script may fail entirely. Empty sub-folders may also cause it to fail. I'll see if I can whip up a fix for that at a later date.
You can do this in two ways:
- Navigate to your book folder in a terminal, and run
wordwatcheron its own. Just like that. - Run the script from any folder you like, so long as you point it to the book folder, like so:
wordwatcher /full/path/to/your/book/
At this point, the text files mentioned above will be created in your $HOME/streaming folder. Remember to leave the terminal window open, or the script will stop updating your word count as you type.
Side note: I use the Terminal plugin for Obsidian so I can just run the scripts from my editor, like so.
With OBS, it's pretty simple. Just add text sources to your scene, go right click on them, and set them to display text from your files in the streaming folder you made earlier.
- currentcount.txt will contain the word count of whichever file in your book folder you edited last.
- fullcount.txt will contain the word count for the entire book folder (well, all the words in markdown files).
- currentfile.txt will show the name of the last file you edited in your book folder.
- currentfolder.txt will show the name of the subfolder your last edited file is in, if any.
Just add those text files to your scene, style the text however you want, place it wherever you want. As long as the script is running in a terminal, your word count and other file information will update live.
Get cracking and have some fun writing on stream, and watch the number go up.
Here are a couple of extra things you might want to check out:
- In my OBS setup, I use the Pthread text plugin for OBS to replace the default Freetype text source you're stuck with on Linux. It enables some simple text animations when the file changes, so that's awesome.
- To get the typing sounds, I use the Click Clack plugin for Obsidian, and the Waveform plugin for OBS to give a visual representation of my typing (see the upper-right) corner in the screenshot or video.
But most of all, have some fun with it!
Because I'm not that good at batch scripting or Powershell, and I do my writing on Linux anyway.
Because I am, and this is important to understand, Not A Real Programmer. I am a rank fuckin' amateur, and you get what you get.
No.
Rude. But if you feel compelled to make an Obsidian plugin that does this better, I'm in.
I don't want to insult you; I just have some ideas/pull requests that might help your script improve.
As long as there's no gen AI crap, I'm in. Please, by all means, teach me your ways. And if anyone wants to contribute a Windows-compatible script to go alongside the Linux scripts, that'd be cool.


