setColorで予定の色変更
Google Apps Scriptで予定の色を変更する際はsetColorを使用するのだが色番号で指定しているコードが多い。
色番号で指定すると何の色が指定されているかわかりにくいため、なるべくカラー名(Enum Color)で指定したほうが良い。
function myFunction() {
const calender = CalendarApp.getDefaultCalendar()
const now = new Date()
const addZero = (n) => ('0' + n).slice(-2)
const [year, month, date] = [now.getFullYear(), addZero(now.getMonth() + 1), addZero(now.getDate())]
const startDate = new Date(`${year}/${month}/${date} 12:00`)
const endDate = new Date(`${year}/${month}/${date} 13:00`)
const event = calender.createEvent(
'昼休み',
startDate,
endDate,
)
event.setColor(CalendarApp.EventColor.PALE_RED)
}
Googleカレンダーの予定に指定できる色は11種類あり、以下の色が存在する。
Property | Description |
---|---|
PALE_
|
Pale Blue ("1" )
|
PALE_
|
Pale Green ("2" )
|
MAUVE |
Mauve ("3" )
|
PALE_
|
Pale Red ("4" )
|
YELLOW |
Yellow ("5" )
|
ORANGE |
Orange ("6" )
|
CYAN |
Cyan ("7" )
|
GRAY |
Gray ("8" )
|
BLUE |
Blue ("9" )
|
GREEN |
Green ("10" )
|
RED |
Red ("11" )
|