Using Jamie Rubin’s google word count tracker with Scrivener – without effort

Jamie Rubin gave us a Halloween present this year by adapting his set of Google scripts that track changes, word count, and progress to be able to handle txt files in your google drive.

Of course, my first thought was how to apply this to Scrivener. At first, I thought I could use Scrivener’s sync folder to accomplish this. That would only work well with some tweaking that would affect my other workflows, and force me to work on only one project at a time. You see, Scrivener expects that when you setup a sync folder, it’s dedicated to the project you’re working with. On top of that, it wants to put all of the text files in a Draft folder. So if you have two or three projects going, you have two or three sync folders, each with it’s own Draft folder. With NaNoWriMo on the horizon, time was of the essence, so I settled for doing text compiles of my novel as I worked on it.

That had two big problems.

  1. It meant I had to remember to compile every day. If you know anything about me, its that remembering to hit a button every day for a month (or longer) is going to have occasional failures.
  2. Although Google will let you store files of various sizes on your drive, Jamie’s scripts rely on Google’s api for  accessing them to get stats and do comparisons. Unfortunately, that means that once your file is more than 20k or so, its too big for the scripts to work with. Think that’s big? My small novel of 70k words had to split into three files in order for the scripts not to die on me.

For the remainder of NaNoWriMo, that’s what I did. I finished writing that novel yesterday, so today I decided to correct this process. I’m on a Mac, and these instructions are very Mac specific (or Linux, but certainly not Windows, at least not without some cygwin – sorry!) What I’ve finally settled on works without me needing to remember to hit a button, without any special changes to Jamie’s scripts. What I did have to do, though, is learn to treat the folder that Jamie’s scripts are watching less like a place I can write, and more like a destination for my files.

Here’s what I’ve done:

  1. In my project, setup sync to folder. I like to put this on dropbox (so I can use an editor on other machines to work with the files), but that’s optional.
  2. Make sure you are putting text files in your sync folder, and only grabbing what you want to grab – what you’ve written, not research, etc.
  3. I wrote a small script that roots through my export folder, grabs text files that are new, copies them to my Google drive – and renames them as it does so, prepending the project name. Why? Because I typically have a structure of Chapter/Scene, where Chapter is the POV, and the file that makes up a scene is literally named Scene. When Scrivener exports this, what you get are a lot of Scene’s with numbers attached to them. By prepending the project name, what ends up in my Google folder is still unique. Finally, I have a cron job that runs a minute before midnight to grab all of my files. The script is simple:


# Ignore space in file names
export IFS='


# Get a list of directories you've exported
for x in `ls $SE`; do
# Just to be safe, make sure we have a Draft directory - otherwise its just flotsam
if [ -d "${SE}/${x}/Draft" ]; then
# paranoia - making sure spaces in the path are ok
path=`echo ${SE}/${x}|sed -e "s| |\\ |g"`
# Find txt files that are less than a day old in our export dir
for file in `find ${path} -name "*.txt" -type f -mtime -1d`; do
# Just grab those files that actually have more than one 2 words - this eliminates things like the directory files
if [ `wc -w ${file}|awk '{print $1}'` -gt 2 ]; then
# Build our new file name
newf=`echo $file | sed -e "s|${SE}/${x}/Draft/||g"|sed -e "s| |_|g"`
# Rsync the file to your google path [FIX THIS] - rsync preserves timestamps
rsync -av $file $HOME/Google/Writing/${x}-${newf}

The cronjob is really simple:

59 23 * * * $HOME/where/I/put/my/scripts/scrivener2google >/dev/null 2>&1

I realize there’s a few things here are technical. If you have questions, let me know!