Auto Block Time on Your Work Google Calendar for Your Personal Events

Will Roman
6 min readApr 19, 2017

--

Do you manage multiple Google calendars to keep your life organized? If you’re like me, you have at least one personal events calendar and another for work items. You need to keep your work calendar up-to-date so that coworkers know when they can invite you to meetings. You must also incorporate your personal events to avoid hidden conflicts.

The obvious solution is to keep one calendar with all your events. Another might be to invite your work calendar to your personal calendar events, thereby filling the time slot on both. You could even create events on both calendars simultaneously.

But these solutions require either double entry or the exposure of personal event details to coworkers and clients. What if you want this process done automatically? What if you want your personal life kept private?

The instructions below enable you to automatically keep your calendars in sync. You may also keep event details private if you so desire. We will use a Google Apps Script hosted on Google Drive to read one calendar and automatically block the corresponding times on another.

The Preparation

This technique assumes that you use Google Calendar for both your work and personal events. It also assumes these two calendars utilize separate Gmail or G Suite logins. You’ll be making a few changes to your settings and finally creating a Google Apps Script to connect everything. For the non-technical, it’s an easy process and I’ll walk you through each step below.

Sharing and Permissions

The first step is to share your personal calendar with your work account and grant the proper permissions. Log in to your personal Google Calendar account. Click the gear icon in the top-right corner of the page and then click “Settings” from the menu.

Next click the the blue “Calendars” tab along the top. This displays all the calendars on your account. Locate the name of the one you want to share and follow the row to the far right. Click the text “Share this calendar” or “Shared: Edit settings.”

Under the heading “Share with specific people” you can add people to share this calendar with. Enter your work email and ensure “See all event details” is selected under Permission Settings. Click “Add Person” and then “Save.”

Calendar ID

You will need the unique calendar identification of your personal calendar. While still on the sharing page, click the “Calendar Details” tab. Scroll down and locate “Calendar Address:” in the left column. Directly to the right is a green “ICAL” button, a blue “HTML” button, and finally the calendar ID. If you are linking the primary calendar of a Gmail account, then the calendar ID will be your Gmail email address. Otherwise it will be a string of characters that ends with “@group.calendar.google.com.” Keep this available for when you edit the script later on.

Connect Google Apps Script

Google Apps Script must be connected in order to host the script. Log in to your work Google Drive account. Navigate to your My Drive folder on drive. (If you’re not a regular user of Google Drive, you can launch the service by clicking the grid icon in the top-right of the page while viewing Gmail or Google Calendar and clicking the icon labeled “Drive.”)

Click the large “New” icon in the top-left of the page. Hover over “More” and then click “+ Connect More Apps” from the menu. This will open a “Connect apps to Drive” window. Type “script” into the search bar and press “enter/return” on your keyboard. Google Apps Script should be the first option. Press the “+ connect” button. You can now close this window.

Executing the Script

Powering this solution is a Javascript snippet hosted on Google Drive that runs in a Google Apps Script file. The code itself is embedded below and the setup instructions follow immediately after.

Create the Google Apps Script File

Navigate to your My Drive folder in Google Drive on your work account. From the “New” button, hover over “More” and click the “Google Apps Script” option that now appears. Click the “Untitled project” text at the top of the screen and enter an easy to remember name for your new script.

Erase the initial code that appears in the “Code.gs” frame. Copy and paste the code above snippet from this page into that frame.

Add Your Calendar Details

The third line contains the only item that you must modify in order for the script to function properly. Replace the XXXXXXXX code—leaving the quotation marks in place—with the calendar ID that you located earlier.

Press the play icon to run the script. You will need to grant the script permission to manage your Google Calendar. Check your primary work calendar to verify that the script is blocking the time slots properly.

Automation

The final step is to schedule the script to run automatically. Click the clock icon to the left of the play icon. This will open the “Current project’s triggers” window. Click the “No triggers set up. Click here to add one now.” text to add a new trigger.

The default trigger will run the script every hour. If you’d like to change the frequency, you may do so by adjusting the dropdown lists. Click “Save” once you are satisfied with the trigger frequency.

That’s it! Your work calendar will now automatically block off time to match the events you create on your personal calendar. New items on your work calendar will be titled “Booked” and hide any additional event details.

Additional Customization

There are additional variables you may edit to better suit your needs.

  • Line 8: set the number of days in advance to monitor and block off time. The default is set to 30 days. Change the “30” to the number of days in advance you would like the script to monitor.
  • Line 41: the script as written does not block off time for events on Saturday and Sunday. Delete everything after the word “else” in order to automatically block off time for events on all seven days of the week.
  • Line 43: blocked off calendar events are titled “Booked” by default. Change that text here to reflect what you would like event titles to be.
  • Line 45: alternatively the script can replicate your personal events verbatim on your work calendar, including titles, locations and descriptions. Completely delete line 43 and delete the first two forward slashes on line 45 to enable this option.
  • Line 47: a notification is created by Google Calendar for all new events by default. This script removes those notifications for the events it creates. If you’d like to turn those notifications back on, delete all of line 47.

Limitations

The original iteration of this code was written by Debsankha. I found a blog post of his from 2011 and expanded upon what he posted. I’m not a coder and create things merely by pattern matching. Therefore some obvious limitations exist in this script.

The script does not monitor for events that are removed from your personal calendar. If you remove an event from your personal calendar and the script created a matching “Booked” event on your work calendar, you will need to manually remove that “Booked” event.

The script only monitors a single calendar. You could create multiple Google Apps Script files and set each one to monitor a different calendar as a work around. Alternatively someone could add an array function to this code.

I hope this script makes your life a small amount easier by eliminating a minor annoyance and replacing it with a little automation.

--

--