Googleカレンダーの予定を作成する(GoogleAppsScript)


Calendar.createEvent

gcal.ts
function createEvent() {

  const title = 'タイトル';
  //予定時間の設定
  //実行日12:00から
  let startTime = new Date();
  startTime.setHours(12); 
  startTime.setMinutes(0);
  //実行日13:00まで
  let endTime = new Date();
  endTime.setHours(13); 
  endTime.setMinutes(0);
  //オプションを追加
  const options = {
  //   description:'説明', 
  //   location:'場所',       
  //   guests:'[email protected]', //ゲスト
  //   sendInvites:true           //招待メールの送信
  }

  //デフォルトカレンダーに予定を作成
  const calendar = CalendarApp.getDefaultCalendar();
  // //IDでカレンダーを指定する場合
  // var calendar = CalendarApp.getCalendarById('{{id}}@group.calendar.google.com');
  const event = calendar.createEvent(title, startTime, endTime, options);
  Logger.log('createEvent: ' + event.getTitle());  //createEvent: title

}

繰り返し予定の作成では,明日以降にも予定が表示されてしまうので,
時間主導型トリガーを毎日0時に設定し,当日のみ表示しています。

Reference

https://developers.google.com/apps-script/reference/calendar/calendar