® Ben Wilson Writes

Automating Scrivener: Wordcount Log

Scrivener 2.0 for Mac. Screenshot of corkboard overview. by Morten Oddvik/Flickr is licensed under CC BY 2.0

Recently, Jamie Rubin talked about using GitHub as an author. I took his article as a challenge to automate Scrivener word count logs and automatically commit changes to Scrivener. This article discusses how I automatically process the Scrivener wordcount into a log file.

A lot of people think of GitHub as a tool for geeks. While that may be true, there are a lot of things you can do that are not technologically related. For example, the Github Services team uses GitHub. As an organization, GitHub is committed to keeping all relevant organizational learning in their own tool.

Authors don’t have to be technology geeks, but it helps. As I abandon my old toolchain, I found myself wondering how I was going to maintain my online progress logs…or as 2015 showed, lack of progress.

My old toolchain comprised a self-authored Ruby gem I called Bookmaker, which ultimately reflects that you can waste more time tinkering with your tools than you can crafting. I started to re-engineer Bookmaker before the challenge. It was “easy” to get the data: I would iterate over the LaTeX files in the target directory, run detex on each file and pipe to wc, and sum the total. Then I would add that data to a JSON file that feeds my progress logs. The next time I committed a change to this website, those logs would be published.

What follows should work on Mac OSX or Linux without issue. If you’re using Windows, then I’m not sure I can help you. I’m a UNIX guy from way back.

Processing Scrivener Wordcounts

In Scrivener, it’s a lot easier. The GitHub Gist below documents the minimum effort required to pull the data out of Scrivener using Crontab (how to use Crontab). All it will do is aggregate a file with the data. You’ll have to figure out your own way to parse it from there.

If you’re looking for something a bit more complex, I’ve published a gist of how I pull the data down and aggregate my wordcount log. (See ScrivxWordCount.rb) That script is missing the config YAML file. If you’re going down this path, I anticipate that you know how to read Ruby and can figure out from the code what you need to put in that file. You’ll also note the script is not fully optimized, which is an artifact of my having pulled out some portions of the code. To use this script, you’ll need to initialize a JSON file (put “{}” in the JSON file).

I have a separate script that takes this data and forms the data I use in my progress. I’ll write about that in a subsequent article.

Automating the Script

There are two options here for a Mac OSX user: crontab or Launchd. The preferred protocol is Launchd. When you shut down your computer, or it goes to sleep, crontab will not execute. Launchd, on the other hand, should run as soon as wake or boot is complete if it did not run at its scheduled time. My launchd gist is what I’m using. Note that it executes 5 minutes before midnight each day.

Because you’re grabbing daily word counts, it is important that Scrivener be configured to reset the session count at midnight. How do you do this?

  1. Cmd + Shift + T (⇧⌘-T) activates the Project Targets panel.
  2. Click Options
  3. Under the Session Target heading, set the dropdown to “Reset Session Count at Midnight” (the screen shot below shows this step graphically)

Screenshot of Session Target dropdown at correct setting.


You may need to make a few tweaks to make it work for you. I hope this helps you pull out your Scrivener wordcount progress as you need. Next time, I’ll share how I put this data to work in my progress charts.

We use cookies to improve your experience on our website Okay Learn More