Skip to content

Instantly share code, notes, and snippets.

@gargomoma
Last active June 14, 2022 05:18
Show Gist options
  • Save gargomoma/c1c13d7a03c944b4c0444720c2175c8c to your computer and use it in GitHub Desktop.
Save gargomoma/c1c13d7a03c944b4c0444720c2175c8c to your computer and use it in GitHub Desktop.
Pulls today's events from GCalendar by using getEventsForDay.
/* In case of inconsistencies - Check:
https://stackoverflow.com/questions/11870304/google-apps-script-geteventsforday-returns-invalid-recurring-events
*/
function EventsToday() {
var user = Session.getActiveUser().getEmail(); /*The mail will be sent to the user running the script*/
var startOfDay = new Date();
var events = CalendarApp.getDefaultCalendar().getEventsForDay(startOfDay);
var evlist = 'Hey!! These are the events you have for today<br>';
Logger.log('Number of events: ' + events.length);
for(var e = 0;e<events.length;e++){
/*Translates event time into readable time*/
var HumanTime = Utilities.formatDate(events[e].getStartTime(), Session.getScriptTimeZone(), "HH:mm:ss dd/MM/yyy");
evlist = evlist+"<p><b>"+HumanTime+"</b> <br>";
evlist = evlist+"<i>"+events[e].getTitle()+"</i></p>";
}
evlist = evlist + '<br> Timestamp ' + startOfDay
Logger.log(evlist);
MailApp.sendEmail (
user,
'Your schedule for today ' + Utilities.formatDate(startOfDay, "GMT", "yyMMdd"),
'',
{htmlBody: evlist,name: 'Automated mail'}
);
}
@bonelifer
Copy link

Is it possible to have it grab events from more than one calendar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment