Web会議の種類ごとにGASでGoogleCalendarに色付け
twitterで見かけたGoogleCalendarに色付けを実践してみた
準備編
まずは GAS を用意します
実践編
単純にマネするだけだと面白みがないので、Web会議の種類ごとに色を変えてみた。
※ TTP(徹底的にパクる) + アレンジする
function ChangeColor() {
const myCalendar = CalendarApp.getCalendarById('***@gmail.com'); ← 自分のGmailアドレスを設定
const startDate = new Date();
const endDate = new Date();
// startDate.setDate(startDate.getDate() - 14) // ← 過去のスケジュールも含めたい場合設定 (自分はテスト的に含めた)
endDate.setDate(startDate.getDate() + 7);
const myEvents = myCalendar.getEvents(startDate, endDate);
myEvents.forEach((event)=> {
console.log(`処理中: ${event.getStartTime()} ${event.getTitle()}`)
// google meet のチェック https://google.meet
setEventColor(event, "meet.google.com", CalendarApp.EventColor.PALE_GREEN)
// zoom のチェック https://zoom
setEventColor(event, "zoom", CalendarApp.EventColor.BLUE)
// teamsのチェック https://teams.microsoft.com/
setEventColor(event, "teams.microsoft.com", CalendarApp.EventColor.RED)
})
}
const setEventColor = (event, meetingURL, color) => {
reg = new RegExp(`https://${meetingURL}`)
if(event.getDescription().match(reg)){
event.setColor(color)
console.log(`色付け : ${event.getStartTime()} ${event.getTitle()}`)
}
}
※ 念のため、画面ショットもつけておく
イベントトリガー
今回はあくまでk人のカレンダーなので、1日1回動けばいい というフワっとした考えで、真夜中に実施するよう設定
あとがき
まだまだGASに慣れていないので、関数の書き方を別で調べて自分用メモとしてまとめておいた。
自分的にアロー関数がおしゃれなので使いたいけど、毎度調べてて面倒になった。
あと、公開すると思って説明用に コードを色々直してたら、画面ショットでつけたコードからだいぶ変わってしまった。
修正しないところに、性格がよく出てると思う。
あとあと、本当は「宛先に外部の人がいる場合は~」という条件で色付けしたかった。ただ、自分のGoogleCalendarの使い方ではそんな予定無いので一旦諦めた。
参考
https://developers.google.com/apps-script/reference/calendar/event-color?hl=en
この記事が気に入ったらサポートをしてみませんか?