内容
スマートウォッチの通知機能でポモドーロするために作りました。
事前処理としてカレンダー側でポモドーロ用のカレンダーを作るのと通知の設定で5分前30分前を加えてください。
GAS側はポモドーロカレンダー取得→昨日のカレンダー削除→今日のカレンダー製作を日付タイマーで夜中に実行させます。
GAS
function makePomodoro() {
const id = 'ポモドーロカレンダーID'
const calendar = CalendarApp.getCalendarById(id)
const today = new Date;
const y = today.getYear();
const m = today.getMonth();
const d = today.getDate();
const yesterday = new Date(y, m, d - 1);
//昨日のポモドーロの削除。消さなくても良いが見た目が悪くなるので
calendar.getEventsForDay(yesterday).map(function(e) {
e.deleteEvent()
})
const start = 7
const end = 22
for(var t = start; t <= end; t++) {
calendar.createEvent('Pomodoro', new Date(y, m, d, t, 0), new Date(y, m, d, t, 29));
calendar.createEvent('Pomodoro', new Date(y, m, d, t, 30), new Date(y, m, d, t, 59));
}
}
コメント
GoogleカレンダーIDはGoogleカレンダー設定→対象のカレンダーの”カレンダーの統合”の部分にあるカレンダーIDです。(@マークを含む)
参考資料
Calendar Service | Apps Script | Google Developers
https://developers.google.com/apps-script/reference/calendar/
公式のリファレンス。必読。