Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Flare576 committed Dec 7, 2022
1 parent 7f126a8 commit d1b770a
Showing 1 changed file with 77 additions and 58 deletions.
135 changes: 77 additions & 58 deletions docs/MERGE_CALENDARS_TOGETHER.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,66 +33,21 @@ Throughout this doc I use two terms a lot:
* Rename the duplicates with the Prefix to allow `MergeCalendarsTogether` to manage those events as
Merged events

## Microsoft Accounts

For each of your Microsoft accounts, you'll need to setup a new Application in the Azure Management
tool. Once you've created the Google script in Step 3 below, click on the "Project Settings" gear
icon on the left, then copy the Script ID. Then:

1. Generate a new "App Registration"
- Go to https://aad.portal.azure.com
- Click "Azure Active Directory" on left
- Click "App registrations" on sub-panel
- Click "New Registration" at top
- Provide name (e.g., "Calendar Merge")
- Leave "Accounts in this organizational directory only" selected
- Choose "Web" from the "Redirect URI" dropdown, and enter (replace your ScriptId from above in the URL)
```https://script.google.com/macros/d/ScriptId/usercallback```
- Click Register
1. Add Calendar.ReadWrite Permissions
- Click "API Permissions" on sub-panel
- Click "Add Permission" under "Configured permissions"
- Click large "Microsoft Graph" card on right
- Click "Delegated Permissions"
- Search/Find "Calendar" and choose "Calendars.ReadWrite"
- Click "Add permission"
1. Obtain a Client Secret for your Google Scripts project
- Click "Certificates & secrets" on the subpanel
- Click "New client secret" under "Client Secrets" tab
- Enter meaningful Description (e.g., "Google Script")
- Set Expires to 24 months (or however frequently you want to go through this again)
- Click Add
- COPY THE VALUE - this is the only time you'll be able to see the value, and if you don't copy it you'll need to
repeat this step
1. Allow Access tokens from Authorization endpoint
- Click "Authentication" on the subpanel
- Scroll to the bottom of the screen and click "Access tokens (used for implicit flows)"
- Click Save at the bottom of the page
1. Acquire your ClientID an TenantID
- Click "Overview" on the subpanel
- Copy your "Application (client) ID" and "Directory (tenant) ID"
1. Update the Google Apps Script
- Fill out the "CALENDERS_TO_MERGE" section, using "microsoft" for the `provider`
- Click the "+" next to the Library button on the left and enter
`1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`
> Note: this the [Google OAuth Library]
- Click Lookup, then click "Add" (Default version/Identifiers are fine!)
1. Select "ShowAuthorizationURLS" from the "Run" dropdown
1. Open provided URL(s) in another browser window
- Click your email address or login
- Verify the name you used in Step 3 is present in the window.
- Click Acccept
- You'll be redirect back to Google - Login with the account you started your project in.

## Getting Started

1. Make sure every calendar you want sync is shared with the account that will run this script
1. Make sure every Google calendar you want to sync is shared with the account that will run this
script
1. Log into the account that holds the shared calendar and go to the [Google Apps Scripts] website.
1. Click on "New Project".
1. Replace everything in `Code.gs` with the contents of [MergeCalendarsTogether.gs].
1. Update `CALENDARS_TO_MERGE`, `SYNC_DAYS_IN_PAST`, and `SYNC_DAYS_IN_FUTURE` variables. Be sure to save.
1. Create a new file of type=`Script` called `BatchRequests.gs` (note: the file extension is automatically added) with the contents of [BatchRequests.gs]
1. Click the `Project Settings` Gear icon on the left panel. Check the `Show "appsscript.json" manifest file in editor`. Go back to code editor on the left, and update its content with [appsscript.json].
1. Update `CALENDARS_TO_MERGE`, `SYNC_DAYS_IN_PAST`, and `SYNC_DAYS_IN_FUTURE` variables. Be sure to
save.
> If one or more of the accounts you're syncing is a Microsoft account, you'll need to follow
> the [Microsoft Accounts](#microsoft_accounts) steps below to get the required information
1. Create a new file of type=`Script` called `BatchRequests.gs` (note: the file extension is
automatically added) with the contents of [BatchRequests.gs]
1. Click the `Project Settings` Gear icon on the left panel. Check the `Show "appsscript.json"
manifest file in editor`. Go back to code editor on the left, and update its content with [appsscript.json].
1. Open the `Code.gs` file again
1. run the script for the first time (also acts as a manual trigger in the future):
- Select the `MergeCalendarsTogether` function from the dropdown to the right
Expand All @@ -108,8 +63,10 @@ icon on the left, then copy the Script ID. Then:
1. Click on `Triggers` clock icon on the left panel to add a trigger. Click on `Add Trigger`.

- You have two choices, "Time-driven" or "From calendar".
- Time-driven will run every X minutes/hours/etc. Use this if you have calendars that update frequently (more than 5-10 times in a 15 minute timespan)
- Time-driven will run every X minutes/hours/etc. Use this if you have calendars that update
frequently (more than 5-10 times in a 15 minute timespan)
- "From calendar" will run when a given calendar updates. Use this if you want instant merging.
> **NOTE**: "From calendar" is not compatible with Microsoft accounts at this time
a. **Time-driven**

Expand All @@ -134,6 +91,65 @@ icon on the left, then copy the Script ID. Then:
for the timer/a new calendar event to do the sync
1. Enjoy!

## Microsoft Accounts

For each of your Microsoft accounts, you'll need to setup a new Application in the Azure Management
tool.

1. Acquire the ScriptId of your Google Apps script
- After completing Step 3 above, click Project Settings gear on left
- Copy ScriptId from "ID's" section
1. Generate a new "App Registration"
- In another tab/window, Log into https://aad.portal.azure.com
- Click "Azure Active Directory" on left
- Click "App registrations" on sub-panel
- Click "New Registration" at top
- Provide name (e.g., "Calendar Merge")
- Leave "Accounts in this organizational directory only" selected
- Choose "Web" from the "Redirect URI" dropdown, and enter (replace your ScriptId from above in
the URL)
```https://script.google.com/macros/d/ScriptId/usercallback```
- Click Register
1. Add Calendar.ReadWrite Permissions
- Click "API Permissions" on sub-panel
- Click "Add Permission" under "Configured permissions"
- Click large "Microsoft Graph" card on right
- Click "Delegated Permissions"
- Search/Find "Calendar" and choose "Calendars.ReadWrite"
- Click "Add permission"
1. Obtain a Client Secret for your Google Scripts project
- Click "Certificates & secrets" on the subpanel
- Click "New client secret" under "Client Secrets" tab
- Enter meaningful Description (e.g., "Google Script")
- Set Expires to 24 months (or however frequently you want to go through this again)
- Click Add
- **COPY THE VALUE** - this is the only time you'll be able to see the value, and if you don't copy it you'll need to
repeat this step
1. Allow Access tokens from Authorization endpoint
- Click "Authentication" on the subpanel
- Scroll to the bottom of the screen and click "Access tokens (used for implicit flows)"
- Click Save at the bottom of the page
1. Acquire your ClientID an TenantID
- Click "Overview" on the subpanel
- Copy your "Application (client) ID" and "Directory (tenant) ID"
1. Update the Google Apps Script
- Fill out the "CALENDERS_TO_MERGE" section, using "microsoft" for the `provider`
1. Add the Oauth Library to the project
- Click the "+" next to the Library button on the left and enter
`1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`
> Note: this the [Google OAuth Library]
- Click Lookup, then click "Add" (Default version/Identifiers are fine!)
1. Authorize your app to use your account
- Select "ShowAuthorizationURLS" from the "Run" dropdown
- Click Run; to console at the bottom of the editor will have a URL for each Microsoft account
you've setup
- Open provided URL(s) in another browser window
- Click your email address or login
- Verify the name you used in Step 3 is present in the window.
- Click Acccept
- You'll be redirect back to Google - if necessary, login with the account you started your
project in.

## Notes

- Google App Scripts has a daily quota of 5k events created per day. See [Quotas for Google Services]
Expand All @@ -145,8 +161,11 @@ your project again. When you do this, it's best to:

1. Make a backup of your current script by copy/pasting into a text document or other local file
1. Replace everything in `Code.gs` with the contents of [MergeCalendarsTogether.gs].
1. Replace everything in `BatchRequests.gs` with the contents of [BatchRequests.gs]
1. Copy your settings from your backup into the new code, particularly
- CALENDARS_TO_MERGE
> Note: The format of CALENDARS_TO_MERGE changed from version 0.1.x to 0.2.x - copy the info
> carefully!
- SYNC_DAYS_IN_PAST
- SYNC_DAYS_IN_FUTURE
- If you use any other features of the script (e.g., filtering/obfuscation/etc.), copy those
Expand All @@ -159,8 +178,8 @@ your project again. When you do this, it's best to:

## What does this actually do?

Since you're granting this script/app full control over two calendars, I thought it important to
include a bit about what it actually does.
Since you're granting this script/app full control over two (or more!) calendars, I thought it
important to include a bit about what it actually does.

The entire script operates in three parts: 1) Get all events for all calendars for all days in the
range you specify, 2) Separate the events into either Primary (Created outside of the script) or
Expand Down

0 comments on commit d1b770a

Please sign in to comment.