Google Apps Script for Class Schedule Management

The 510 Way !
3 min readJun 23, 2024

--

Brought to you by Ajay Sriram and Vishnu Prasath

This guide will provide you with step-by-step instructions on setting up a script that not only syncs your class schedule with your calendar but also sends you real-time notifications for any class cancellations.

Step 1: Prepare Your Google Sheet

  1. Open Google Sheets: Go to Google Sheets and start a new spreadsheet by clicking on the blank template.
  2. Name Your Spreadsheet: Click on the spreadsheet title at the top and rename it to something meaningful, like “Class Schedule Manager”.

You can find the complete script here !

Step 2: Insert the Script

  1. Open the Script Editor: From your Google Sheets interface, go to Extensions > Apps Script.
  2. Rename the Project: In the Apps Script tab that opens, click on Untitled project at the top left and rename it to "Class Schedule Script".
  3. Paste the Code: Delete any code in the script editor and paste the entire script provided above.

Step 3: Customize Your Script

  1. Set Subject Codes: You need to replace the placeholders for subject codes in the script with actual codes used in your schedule. Look for the targetClasses array in the functions initialCalendarEvents()-Line 13, syncCalendarEvents()-Line 72 and checkcellsandnotify()-Line 209, and update it with your specific class codes. Example:
var targetClasses = ["CS101", "MATH233", "HIST101"];

2. Set Email Address: Change the email address in the sendNotification()-Line 241 function to where you want to receive notifications for canceled classes. Example:

var emailAddress = "your-email@example.com";

Step 4: Set Up Triggers

  1. Open Triggers: Click on the clock icon on the left side of the Apps Script editor to go to the Triggers page.
  2. Add a New Trigger: Click on + Add Trigger in the bottom right corner.
  3. Configure the Trigger:
  • Select main as the function to run.
  • Choose Time-driven for the event source.
  • Set the type to Hours timer and interval to Every hour.

4. Save the Trigger:

  • Click Save.
  • At this point, Google will prompt you to review permissions for accessing Google Calendar, Google Sheets, and sending emails.
  • If your browser blocks the pop-up window (a common scenario), you will need to allow pop-ups for this URL. Check the address bar for a pop-up blocked icon, click it, and choose Always allow pop-ups and redirects from [URL]. Then, click Done and try saving the trigger again.
  • Once pop-ups are allowed, click on the trigger save again, and complete the authorization process by logging in with your Google account and granting the necessary permissions.

Step 5: Monitor and Maintain

  • Adjust as Needed: If your class schedule changes, remember to update the targetClasses in the script and rerun it if necessary.

Important Notes

  • Specific Configuration: The script as provided is configured specifically for managing the 2nd year class schedule at IIM Kozhikode. If you are affiliated with a different institution or need the script for a different purpose, you will likely need to modify the configurations.
  • Service Limits: Google Apps Script might limit the frequency of use after a few months. If you encounter this issue, set up a new Google Sheet and repeat all the steps listed above.
  • Code Customization: Feel free to modify the script to better suit your specific needs or the structure of your sheet.
  • Failure Notifications: To monitor the script’s performance, especially if you are making modifications, set up daily failure notifications. This can be done under the Trigger settings by choosing the ‘Notify me daily’ option for failure notifications.

Also, we’d love to hear about other projects or challenges you’d like to tackle with automation. Let us know what tools or solutions would make your daily life easier, and we might just explore them in future posts!

--

--