我需要计算下几周的事件数量。但我的方法太慢了(工作时间超过 1.5 小时)。我怎样才能加快这个脚本?目前,我每次都获取日历的所有事件weekNumber
......这非常慢,但我无法弄清楚如何只获取一次所有事件并为每个事件设置 weekNumber。
tell application "Calendar"
set theCalendars to name of calendars
repeat with theCalendar in theCalendars
set listCurrentCalendar to {}
set end of listCurrentCalendar to theCalendar
repeat with weekNumber from 1 to 13
set currentWeekMonday to my DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Monday, weekNumber)
set nextWeekMonday to my DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Monday, weekNumber + 1)
set numberOfEvents to 0
set TheEvents to events of calendar theCalendar
repeat with anEvent in TheEvents
set eventStartDate to start date of anEvent
if eventStartDate ≥ currentWeekMonday and eventStartDate ≤ nextWeekMonday then
set numberOfEvents to numberOfEvents + 1
end if
end repeat
set end of listCurrentCalendar to numberOfEvents
end repeat
set end of listData to listCurrentCalendar
end repeat
end tell