Terminal 101: Accessing Google Contacts from the Terminal

Every Monday, we’ll show you how to do something new and simple with Apple’s built-in command line application. You don’t need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type ’em out!

The Contacts app on the Mac is great, but many users rely on Google Contacts to store and view contact cards for people. If you’re not syncing Google Contacts with your Mac or iOS device, then you have to access your contacts from your Google account in a web browser — or not. As we’ll show you today, you can also use the Terminal alongside Google Command Line Tools to access your contacts without ever leaving the command line. Continue reading, and we’ll show you show to list, create, and delete contacts with your Google account. And as a bonus, we’ll also show you how to generate a CSV file containing your contacts as a backup.

Note: If you haven’t already done so, follow our guide from last month to set up your Mac to enable Terminal to talk with Google’s services. The guide can be found here.

Listing Contacts

To list all of your currently stored contacts from your Google account, type the following command:

google contacts list –title “.*.”

After pressing enter, you’ll see your contacts printed to the screen. If you wish to look up a specific person in your contacts, then type the following command to easily search for that person’s contact info:

google contacts list –title “Name”

Replace “Name” in the above command with the name of the person you wish to search for in your Contacts. If the person is found, then their contact information will be printed to the screen.

Adding a Contact

Adding a new contact to your Google account is super-easy. To do it, simply use the following command:

google contacts add “FirstName LastName, email@domain.com”

Replace “FirstName” with the first name of the person you’re adding, “LastName” with the last name of the person you’re adding, and finally, replace “email@domain.com” with the email address of the person you’re adding.

After pressing enter, the contact will be added, but you will not be given a confirmation that it has.

Deleting a Contact

Deleting a contact is just as simple as adding one. To delete one of the contacts in your existing list, use the following command, replacing “FirstName” with the first name of the contact that you wish to delete:

google contacts delete –title “FirstName”

When you press enter, you’ll be prompted to reply with a “y” (yes) or a “n” (no) as to whether you wish to remove the contact from your Google account.

Generating CSV File for Contacts

The Google Command Line Tools are pretty cool, and let you do things without ever having to touch an app or the Google website. One thing that is even easier with the command line is backups. With the Google CLI installed, you can create a backup of your contacts just by typing the following command:

google contacts list –title “.*.” > ~/Desktop/contacts.csv

When run, this command will go to Google, collect all of the contacts in your Google account, and then create a comma separated values (CSV) document called “contacts.csv” on your Desktop that contains the complete listing of your contacts. Pretty nifty, eh? Now you don’t have to worry about losing your contacts. Just perform this command periodically to store a complete backup.

Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article’s author on Twitter.