iCalの年度切り替え

MacOS X の定番スケジュールソフト「iCal」は、過去のデータを一括して消す機能が無い。
カレンダーのカテゴリーを複数作ることが出来るので、年度別に作ることで対処できるのだが、うっかりそのまま使っていたりする。
そこで、指定した日付より古いスケジュール(イベント)を削除するプログラムをApplescriptで書いた。あ、Tiger (MacOS X Ver.10.4) の iCal 2.0以降専用です。

アップルスクリプトは以下のとおり。処理は遅いが頻繁に使うものではないので、ご容赦を。
諄いループになっているのは、Eventを削除すると、次のEventを取得できなくなるので、削除する毎に再度Eventの取得し直しをしているためです。
動作保証は出来ませんので、バックアップを取ってからお試しください。
------ 以下スクリプトのソース --------

display dialog "基準日を下の形式で入力してください。" default answer "2005/4/1"
set inDate to text returned of result
set Today to date inDate
tell application "iCal"
    set allCals to every calendar
    repeat with eachCal in allCals
        set calName to name of eachCal
        display dialog calName buttons {"Delete", "Pass"} default button "Pass"
        set Proc to button returned of result
        if Proc = "Delete" then
            set allEvents to the every event of eachCal
            set procCounter to 0
            set allEvents to every event of eachCal
            set nunberOfEvents to the number of events of eachCal
            repeat while procCounter < nunberOfEvents
                set procCounter to 0
                repeat with eachEvent in allEvents
                    set procCounter to procCounter + 1
                    set sDate to start date of eachEvent
                    if sDate < Today then
                        delete eachEvent
                        exit repeat
                    end if
                end repeat
                set allEvents to every event of eachCal
                set nunberOfEvents to the number of events of eachCal
            end repeat
        end if
    end repeat
    display dialog "iCalのイベント削除処理を終了しました。"
end tell

 起動すると日付を聞いてきますので、基準になる日付(指定した日付
より前の予定を削除します)を入力します。
次に、記録されているカレンダーを順番に表示しますので、処理したい
カレンダーを選びます。
処理しない場合は「Pass」ボタン、処理するカレンダーは「Delete」ボタン。