List of Calendars

I’m obviously being thick here, but I’m trying to get a list of calendars using the Calendar object:
let cal = Calendar.getAllCalendars();

if (cal) {
let title = cal.title;
for (title of cal) {
console.log(“Calendars:”+title);
}
}

But all I get in the log is:
Calendars:[object ActionKit.ScriptObjectCalendar]
Calendars:[object ActionKit.ScriptObjectCalendar]
Script step completed.

Not the titles or names of the calendar. Any ideas, other my bad JS skills?

The Calendar.getAllCalendars() returns an array of available calendars, not a specific calendar object.

Not sure what your end goal is, but you would need a construct more like the below to loop over the calendars returned:

let cals = Calendar.getAllCalendar();

for (let cal of cals) { // loop over array of calendars
    console.log(cal.title);
}

Hope this helps!

Awesome, Thanks. I figured the looping was wrong!

I’m trying to debug a script to figure out why all events for a given Calendar aren’t being returned and I first wanted to make sure I was getting the Calendar names correct, which isn’t always obvious when macOS calls a bunch of calendars just ‘Calendar’ with no opportunity to change it!