I am working in JXA and trying to count the number of events in a calendar. As far as I understand each event in a calendar is an object, in the class calendar.
The example code places the objects in an array and then counts the length of the array, but that can't be the best way to do count the number of objects.
The code runs in ScriptEditor on Mac OS 10.15
var ical = Application('Calendar');
var calOne = ical.calendars[1]
arrEventsInCalOne = [];
i = 0
try {
do {
i++;
arrEventsInCalOne.push(calOne.events[i]().startDate());
} while (i < 100);
} catch (err) {
"No value"
}
arrEventsInCalOne.length
To get the number of events in a single calendar:
Application('Calendar').calendars[0].events.length
To get the number of events in all calendars as a sum total:
Application('Calendar').calendars.events.length