Automated task reminder in Google Spreadsheet: Automatically send deadline notifications via email.

JavaScript

This script utilizes Google Spreadsheet and Google Apps Script to streamline task management. It automatically sends reminder emails for tasks whose deadlines are due tomorrow. This is one example of enhancing productivity by leveraging Google Spreadsheet.

Used Technologies

  • Google Apps Script: Handles the main logic of the script.
  • Google Spreadsheet: Stores and manages tasks and their deadlines.
  • Google Email Service (Gmail): The email service used for sending reminders.

Features

  • The script reads tasks and their deadlines from the Google Spreadsheet.
  • If a task has a deadline set for the day following the script’s execution, a reminder will be sent to the specified email address.
  • Tasks with past deadlines will not be notified.

Sauce Code

JavaScript
function sendTaskReminder() {
  // Get the active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  
  // Get the sheet named "Tasks"
  var sheet = ss.getSheetByName("Tasks");
  
  // Check if the sheet exists
  if(sheet === null) {
    Logger.log("The sheet named 'Tasks' was not found.");
    return;
  }
  
  // Get the range where tasks and due dates are stored (in this example, Column A for tasks, Column B for due dates)
  var tasks = sheet.getRange("A2:B10").getValues();
  
  // Get today's date and calculate tomorrow's date
  var today = new Date();
  var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000)); // 1 day later (24 hours * 60 minutes * 60 seconds * 1000 milliseconds)
  
  // Check each task
  for (var i = 0; i < tasks.length; i++) {
    var taskName = tasks[i][0];
    var dueDate = new Date(tasks[i][1]);
    
    // If the due date is tomorrow, send an email
    if (dueDate.toDateString() === tomorrow.toDateString()) {
      var email = "your_email@example.com"; // Please change this to your own email address
      var subject = "Task Reminder: " + taskName;
      var body = "The following task is due tomorrow: " + taskName + " (Due Date: " + dueDate.toDateString() + ")";
      MailApp.sendEmail(email, subject, body);
    }
  }
}

// MIT License
// Copyright (c) 2023 [ANJI]
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

How to Use

  1. Create a Google Spreadsheet.
  2. Name the sheet “Tasks”, and enter task names in Column A and due dates in Column B.
  3. Add this script to your Google Spreadsheet.
  4. In the code, replace the part var email = “your_email@example.com“; with the email address where you’d like to receive notifications.
  5. Either manually run the script or set up a time-based trigger to execute it automatically.

How to Set Up a Time-Based Trigger

  1. In the Google Spreadsheet interface, go to Extensions → Apps Script.
  2. In the Apps Script interface, click on the triggers icon in the upper-left corner (it looks like a clock).
  3. Click the “+ Add Trigger” button at the bottom.
  4. For “Function to Run”, select sendTaskReminder, and for “Event Source,” choose “Time-driven.”
  5. Select the frequency at which the script will run (e.g., every day at 9 a.m.).
  6. Click “Save.”
     

By following these steps, the script will automatically run at the specified time, and email notifications will be sent for tasks that meet the conditions.

コメント

タイトルとURLをコピーしました