This Google Apps Script automatically adjusts travel events in your Google Calendar that were created by Reclaim.ai. It uses the Google Maps API to calculate more accurate travel times based on real-time traffic data and applies custom time-based multipliers for rush hours and busy periods.
- Identifies events with locations in your Google Calendar
- Finds associated travel events created by Reclaim.ai
- Calculates travel times using Google Maps API, considering traffic conditions
- Applies custom multipliers for rush hours and busy weekend times
- Adjusts the duration of existing travel events
- Works for a configurable number of days into the future
- A Google account with access to Google Calendar and Google Apps Script
- A Google Cloud Project with the Distance Matrix API enabled
- An API key for the Google Maps API
- Reclaim.ai set up with your Google Calendar
-
Create a new Google Apps Script project:
- Go to script.google.com
- Click on "New project"
- Delete any existing code in the script editor
-
Copy the entire contents of
calendar_travel_time_adjustment.gs
from this repository and paste it into your Google Apps Script editor. -
Configure the script: In the configuration section at the top of the script, update the following variables:
CALENDAR_ID
: Replace with your Google Calendar ID (e.g., '[email protected]' or the ID of a specific calendar)HOME_ADDRESS
: Update with your home or default starting location (e.g., '123 Main St, Anytown, ST 12345')API_KEY
: Replace with your Google Maps API key- Adjust other configuration variables as needed:
DAYS_TO_PROCESS
: Number of days to look ahead in the calendarTRAVEL_EVENT_PREFIX
: The prefix used by Reclaim.ai for travel events (default is '🚌 Travel')MAX_HOURS_BEFORE_AFTER
: Maximum hours to look before/after an event for travel events- Time-based multipliers and rush hour definitions
-
Save the project by clicking on File > Save or using the floppy disk icon.
- In the Google Apps Script editor, select the
adjustTravelEvents
function from the dropdown menu next to the "Run" button. - Click "Run" to execute the script.
- The first time you run the script, you'll need to authorize it to access your Google Calendar and make external API requests.
- Check the execution log for any errors or messages.
To have the script run automatically:
- In the Google Apps Script editor, click on "Triggers" (clock icon) in the left sidebar.
- Click "+ Add Trigger" at the bottom right of the page.
- Set up the trigger with the following settings:
- Choose which function to run:
adjustTravelEvents
- Choose which deployment should run:
Head
- Select event source:
Time-driven
- Select type of time based trigger:
Day timer
- Select time of day: Choose a time when your calendar is least likely to be in use (e.g., 2:00 AM to 3:00 AM)
- Choose which function to run:
- Click "Save"
The script will now run automatically once per day, adjusting travel events for the upcoming days as configured.
- The script fetches all events for the configured number of days ahead.
- For each event with a location:
- It looks for associated travel events created by Reclaim.ai (identified by the
TRAVEL_EVENT_PREFIX
). - If found, it calculates the travel time using the Google Maps API, considering traffic conditions.
- It applies time-based multipliers for rush hours and busy periods.
- It adjusts the duration of the travel events based on the calculated travel time.
- It looks for associated travel events created by Reclaim.ai (identified by the
You can customize the script by modifying the following variables in the configuration section:
DAYS_TO_PROCESS
: Number of days to look ahead in the calendarMAX_HOURS_BEFORE_AFTER
: Maximum hours to look before/after an event for travel eventsWEEKDAY_RUSH_HOUR_MULTIPLIER
andWEEKEND_BUSY_HOUR_MULTIPLIER
: Adjust these to change how much extra time is added during busy periodsWEEKDAY_RUSH_HOURS
andWEEKEND_BUSY_HOURS
: Modify these to match the typical busy hours in your area
- If you encounter errors, check the execution log in the Google Apps Script editor for detailed error messages.
- Ensure your Google Maps API key is valid and has the necessary permissions.
- Verify that your Calendar ID is correct and that you have access to the calendar.
- If travel events are not being adjusted, make sure the
TRAVEL_EVENT_PREFIX
matches the prefix used by Reclaim.ai in your calendar.
Contributions to improve the script are welcome. Please feel free to submit a pull request or create an issue if you have any suggestions or encounter any problems.
This project is licensed under the MIT License - see the LICENSE file for details.
This script is provided as-is, without any guarantees. Please use it responsibly and ensure you have the necessary permissions to modify your calendar events and use the Google Maps API.