Calculate the age of a person and write it to the event's description in your birthday calendar using Google Apps Script
This script uses Google Apps Script to access one's Google Calendar and calculate the age on a person's birthday. In the best case you have a custom calendar where your birthdays are stored at. If not, uncomment line 20 and use the filter function at the bottom.
- Head to https://script.google.com/home/my and create a new project. Rename the existing file Code.gs to your liking and paste the code from calculateAge.gs.
- Paste your calendar ID in line 9 (you can find it in the Google Calendar Settings)
- Make sure to add the birth year of a person to the location field (or customize the script)
- Customize the message in line 36
- Hit run and see the messages appear in your calendar events for the current year!
- Create a trigger to run this every year to calculate the correct age
First of all, thanks for sharing the code! It has been really helpful!
I never got the reminders to work properly so I did some experiments. I tried to get the all-day default notifications to be assigned to a new calendar event and it does work. The problem is that when executing the script (specifically when setting the description - e.setDescription()) the reminders/notifications are deleted!! I tried checking if each event was in fact an all day event (isAllDayEvent()), then I tried e.removeAllReminders() followed by e.resetRemindersToDefault(). What this did was applying the non all-day default notifications to the event (in spite of being an all day event) and deleting the previous ones set when creating the event.
Later I tested the effects of the scripts when setting different defaults to different times:
I wondered if it was the API that was creating a new event and deleting the previous one whenever the Description of the event is set, meaning that the other event metadata would be copied using its own API(????), meaning that it would abide to the restrictions of the api itself (addPopupReminder() -> must be at least 5 minutes before the event) but in this case the midnight reminder would be deleted!!!
In conclusion, it seems that every all-day default reminder/notification set to the actual day of the event is removed (except for the one at midnight) and only the ones set to prior of the day of the event are kept. I couldn't find anything that could lead to this problem.
Do you think this is a bug? Do you think there's a workaround?
EDIT:
![1111](https://user-images.githubusercontent.com/59342151/211217415-0cc94e4f-9c9a-4b56-9caa-48c215455631.png)
![2222](https://user-images.githubusercontent.com/59342151/211217737-4b9c0863-fc3d-4b5a-a4ab-0b116a3cf973.png)
-It seems that running the script is locking the ability to edit notification time! When I try to change the notification parameters of an all day event that repeats yearly it doesn't save, despite giving that feedback. All other parameters (title, description, date and time, visibility, etc) are changeable and the changes saved. Non all day and events that don't repeat, do repeat and all day events that don't repeat are not affected, meaning that we can edit every parameter of the event after running the script.
-Another weird thing: whenever I try to change the notification time of a problematic event (event subject to the script's changes) it does not get saved but changing the events date to any other date, makes the supposed unsaved changes appear!
Example:
1- create an all day yearly event with location 2020, a default all day notification of 00:00, at date 24/03/2023
2- run the script
3- description of the event now has changed to "its rachels 30th birthday" and still has the 00 notification
4- I change notification to 00:50 and save
5- IT DOES NOT GET SAVED appearing as follow:
6- change the event date to 25/03/2023
7- IT APPEARS WITH CORRECT NOTIFICATION TIME!!??? as follow:
8- change it back to day 24/03 -> notification time changes back to 00:00!!!!?
9- change the event to 2 days 24/03 to 25/03 -> notification time stays at 00:00!!!!?