An alternative is to create an Array of calendar IDs and iterate through it:
(The benefits of this is that you can later create a sheet with the IDs and read them in, avoiding having to hardcode them in, and possibly hand it off to someone who doesnt know how to code but can update a sheet)
function getCalendars() {
var mycal = new Array(); // Create an Array for the calendar IDs
mycal = ['comp.com_2d3634303139333138363136@resource.calendar.google.com',
'comp.com_3838393135313632343833@resource.calendar.google.com',
'comp.com_3838393135313632343833@resource.calendar.google.com'];
for (var i=0; i < mycal.length; i++) {
var cal = CalendarApp.getCalendarById(mycal[i]);
var events = cal.getEvents(new Date('June 1, 2010 00:00:00 CST'), new Date('June 9, 2016 23:59:59 CST'), {visibility: 'default' || 'public'});
for (var i=0;i<events.length;i++) {
events[i].setVisibility(CalendarApp.Visibility.PRIVATE);
}
}
}
An even better alternative is to create another function to handle the "heavy lifting":
(this makes the code more readable and easier to reuse / modify later)
function makePrivate(calId) {
var cal = CalendarApp.getCalendarById(calId);
var events = cal.getEvents(new Date('June 1, 2010 00:00:00 CST'), new Date('June 9, 2016 23:59:59 CST'), {visibility: 'default' || 'public'});
for (var i=0;i<events.length;i++) {
events[i].setVisibility(CalendarApp.Visibility.PRIVATE);
}
}
function getCalendars() {
var mycal = new Array();
mycal = ['comp.com_2d3634303139333138363136@resource.calendar.google.com',
'comp.com_3838393135313632343833@resource.calendar.google.com',
'comp.com_3838393135313632343833@resource.calendar.google.com'];
for (var i=0; i < mycal.length; i++) {
makePrivate(mycal[i]);
}
}