0

購読しているカレンダーからすべてのイベントを取得し、それらを別のカレンダーの終日イベントに変換するためのアップルスクリプトを書いています。以下は、これまでの私の不完全なコードです。

tell application "Calendar"
    tell calendar "Canvas"
        set listEvents to every event whose allday event is false
    end tell

    tell calendar "Update"

        set noMatchList to {}
        set listAllDayEvents to every event whose allday event is true
        if listAllDayEvents is null then
            set listAllDayEvent to {0}
        end if
        repeat with firstEvent in listEvents
            repeat with secondEvent in listAllDayEvents
                if firstEvent is not equal to secondEvent then
                    set end of noMatchList to firstEvent
                end if
            end repeat
    end repeat
...

私が抱えている問題は、listAllDayEventsnull の場合、つまり Update カレンダーに終日のイベントがない場合、実行が停止し、if ステートメントに到達しないことです。何が問題で、それを回避する方法はありますか?

4

1 に答える 1

1

2つのこと。

null を使用している理由がわかりません。

代わりに {} を使用してください。また、次の変数名の末尾に「s」がありません。

 set listAllDayEvent to {0}

そのはず:

set listAllDayEvents to {0}

アップデート。

また、あなたがやろうとしていることを理解できれば。コードのロジックが少しずれていると思います。

最初の繰り返しでlistAllDayEventsの項目をテストする必要があります。

listAllDayEventsに項目が見つかった場合は、2 回目の繰り返しで一致するかどうかを確認します。

listAllDayEventsに項目がない場合、2 回目の繰り返しに入る必要はありません。

後で処理するために、listEvents の項目を noMatchListリストに追加するだけです。

tell application "Calendar"
    tell calendar "Canvas"
        set listEvents to every event whose allday event is false
    end tell

    tell calendar "UpDate"

        set listAllDayEvents to every event whose allday event is true

    end tell

    set noMatchList to {}

    repeat with firstEvent in listEvents
        if listAllDayEvents is not {} then

            repeat with secondEvent in listAllDayEvents
                if firstEvent is not equal to secondEvent then
                    set end of noMatchList to firstEvent
                end if
            end repeat

        else

            set end of noMatchList to firstEvent
        end if

    end repeat

end tell


注: このコードをテストしたい人へ。それぞれにいくつかのイベントを含む 2 つの新しいカレンダーを作成します。おそらく確立されたカレンダーを使用するのではなく。カレンダーは、特に繰り返しイベントがある場合や数年前にさかのぼる場合、非常に大きくなる可能性があります。これは、スクリプトの実行が完了するのを一日中待っている可能性があることを意味します

于 2013-09-17T17:57:56.677 に答える