In Part 1 of this series we showed you how to use your command line to access Facebook with FBCMD and Twitter with TTYtter. Today you’ll learn how to manage your Google services from the command line.
Note: We have previously written a beginner guide to using GoogleCL, and this article is an add-on to that article with more detailed examples.
Google offers many different services, several of which are available from your terminal with the Python program GoogleCL:
It’s more than likely that your *nix package manager offers GoogleCL in one of its repositories. If it doesn’t, or if you’re running Windows, you can download GoogleCL here or grab the latest source code like this (note that Google Docs are broken in the latest .tar.gz packages from the first link, so I strongly recommend using the Subversion command below):
svn checkout http://googlecl.googlecode.com/svn/trunk/ googlecl-read-only
GoogleCL requires the dependencies Python 2.5, 2.6, or 2.7 and gdata. To see all the different ways you can install GoogleCL, visit the official Install page. Here’s how to install it from the Subversion sources:
cd ./googlecl-read-only sudo python setup.py install
If your default version of Python is not 2.* (you can check with the command
python --version), you’ll have to specify a version when you run setup.py. For example, if your Python version is 2.7, run:
sudo python2.7 setup.py install
Once you’ve installed GoogleCL, you’ll be able to run these commands:
google blogger [arguments] google calendar [arguments] google contacts [arguments] google docs [arguments] google finance [arguments] google picasa [arguments] google youtube [arguments]
Before you can actually use these services, you must authorize GoogleCL. The first time you run a GoogleCL command for a particular service, you’ll be automatically taken to the authorization page in your browser. For example, I ran:
google picasa list-albums #lists your Picasa albums
GoogleCL asked me to specify the user (usually email@example.com, unless you’re using Google services for a different domain name), and then it took me here:
Once I pressed “Grant access,” I went back into my terminal and hit Enter. GoogleCL then listed my Picasa albums along with their URLs:
You can view a complete list of GoogleCL commands by entering
man google in your terminal. I’ll now show a few examples of what you can do.
First configure your blog. In Linux, Mac OS X, or a BSD system, edit “~/.config/googlecl/config”; in Windows 7+, edit “C:\Users\USERNAME\.googlecl”, and in Windows XP edit “C:\Documents and Settings\USERNAME\.googlecl”. Scroll down to the end of the document, where there is a section labeled
[BLOGGER], and add your blog’s information:
blog = The Name of Your Blog skip_auth = True user = firstname.lastname@example.org
Now you can:
List your posts:
google blogger list
Make a new post with tags:
google blogger post --tags "breakup, terminal" "I broke up with my boyfriend today, so I'm disconsolately posting about it from my bash shell." [name of blog, if you have more than one]
Make a new post from a text file and give it a title:
google blogger post --title "I wrote this post in Vim!" blogger-text.txt
Delete a post:
google blogger delete --title "This is a really embarrassing post about my feelings that I will someday regret publishing"
Add an event to your calendar:
google calendar add "MakeTechEasier article due Saturday at 11:59pm" --reminder 2d # GoogleCL will automatically parse the date and time
List all events:
google calendar list
List events in a particular date range:
google calendar list --date 2012-12-25,2013-01-16
Delete an event on a particular calendar:
google calendar delete --cal "My Social Calendar" --title "Lame Party"
For Contacts, you’ll have to provide an authorization token in addition to authorizing GoogleCL in your browser. GoogleCL will walk you through this. Once authorized, you can perform these common tasks:
Add a new contact:
google contacts add "Ms. NewBoss, email@example.com"
List contact information for anyone with a particular string in their name:
google contacts list "Boss"
Add a new contacts group:
google calendar add-groups "Family" "Friends" "Enemies"
List your contacts groups:
google calendar list-groups
Delete a contact:
google calendar delete "Traitor"
Remember that if you installed the stable version of GoogleCL, Google Docs is likely to be broken. Use the Subversion command described in the “Installation” section of this article to get Docs working. Once you’ve provided your authorization key, you can perform these actions and more:
Upload a document:
google docs upload Homework.odt
List all of your documents:
google docs list
Edit a document by name in an editor of your choice:
google docs edit --title "My Hopes and Dreams" --editor emacs
Download a document:
google docs get --title "Mom's Hannukah Wishlist"
Create an album:
google picasa create --title "My Art" --tags art,drawing
Delete an album:
google picasa delete --title "Ex-Girlfriend and Me"
Add a new photo to an album:
google picasa post --title "San Francisco" golden-gate-bridge.jpg
Tag photos in an album:
google picasa tag --title "College" --tags college,UCSC
List photos with a particular tag:
google picasa list --query "GPOY"
Download an album to your Pictures folder:
google picasa get --title "New Girlfriend and Me" ~/Pictures
In the next installment of this article series, we’ll discuss ways to view and download YouTube videos. If you have your own YouTube account, you can manage it with GoogleCL:
List your videos:
google youtube list
Post a new video:
google youtube post --category Music --devtags folk,"The Mountain Goats",live --title "The Mountain Goats live in Portland" tmg_live.ogv
Tag all videos with a certain string in the title:
google youtube tag -n ".*mashup.*" --tags mashup
Delete a video:
google youtube delete --title "V-Day with the Ex"
GoogleCL lets you add many additional parameters to your tasks that I haven’t described here. See this section of the GoogleCL manual to read about them.
Stay tuned for next time, when we’ll talk about using Tumblr, Flickr, and YouTube from the command line!