Automate ALL the Docs!

I’ve been programming a lot lately, mainly to make my own life easier. I usually start something when I’m doing a menial task that a computer could do much more efficiently. As a result, I’ve learned just enough to know what should be possible, but not enough to know when something is a good idea and something is a really dumb idea. This one turned out to be a good idea.

Two months ago, I wrote up a way to automate rubric score reports using docappender in Google Drive. It worked great the first month.

Today, I went back to score a second set of writing prompts with the rubric. docappender works great to do this, but I have to go into Drive and create six separate documents with the class hour as the name for the form to work correctly. Google has no batch-create option, so I had to make each one individually. It didn’t take too long, but it’s something that really should take any quantity of time.

Major props to Ken Bauer and Alan Liddell for pointing me in the right direction. Here’s what to do…

The Script

Computers are good at making documents. One way to do this on a Mac (or Linux, for that matter) is to create a shell script which can be run from the terminal. Alan gave me this little snippet to get me started:


for i in $(seq 1 7);
touch file$i;

That worked great. But, what if I wanted more than seven files? I wanted to give myself a couple variables which would make the script more flexible:


echo "Number of files: ";

read number;

for i in (seq 1 $number);
touch file$i;

And that was all well and good…but what if I wanted a specific prefix? And, could I make it right into a Google Doc? Yes, and yes.


#! usr/bin/env bash
echo "You're about to create a series of files."
echo "Enter the number of files you'd like to create and then push [ENTER]: "

read number

echo "Enter a generic filename and then press [ENTER]: "

read file

for i in $(seq 1 $number);
touch $file$1.doc;

echo "Finished."

Make it better

This was great. I could make files with less than three dozen keystrokes and clicks. But, like any good programmer, I wanted it to be done with even fewer – more automation was needed.

I wanted to make the script executable – I wanted it to run just by typing the name of the program into the terminal. So, I ran chmod +x makedoc (makedoc is what I called the program…real original, eh?) and gave it permission to run. I also added #! /usr/bin/env bash to the first line of the script to make sure it ran with the right kernel.

Then, I copied the script to my computer’s usr/local/bin directory and voila! All I have to do is go to the folder where I want to make the files, open up the Terminal and type in makedoc and make my sequence of files.

Get ready to have your mind blown.

“That’s great to make them on your computer, but you need them on Google Docs to work with docappender. Wasn’t that the point?”

Google Drive allows me to sync certain folders to my computer. The script doesn’t know if I’m in a local folder or one synced from the web. So, all I have to do is cd to the right spot in Terminal and run the script and BOOM – they’re all in Drive, ready to be used.

It’s. awesome.

Right now, it creates a Word document, which can be synced through the Drive folder. I would like to have a way to create a Google Document locally, but takes a little more computing power than I have time for tonight. Perhaps at a later date…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.