0

我需要计算下几周的事件数量。但我的方法太慢了(工作时间超过 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
4

1 回答 1

0

这是一个两周的例子:

set myEvents to {}

tell application "iCal"
    set myCalendars to calendars
    repeat with aCalendar in myCalendars
        set calEvents to (every event of aCalendar whose start date > (current date) and end date < ((current date) + (2 * weeks)))
        if calEvents ≠ {} then set myEvents to myEvents & calEvents
    end repeat
end tell
于 2013-07-29T20:11:06.520 回答