0

我正在编写一个applescript,以从订阅的日历中获取所有事件并将它们转换为另一个日历中的全天事件。以下是我目前不完整的代码:

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
...

我遇到的问题是如果listAllDayEvents为空,即更新日历中没有全天事件,执行停止并且永远不会进入 if 语句。有什么问题,有没有办法解决它?

4

1 回答 1

1

两件事情。

不知道你为什么使用null。

请改用 {}。您还错过了变量名称末尾的“s”:

 set listAllDayEvent to {0}

它应该是:

set listAllDayEvents to {0}

更新。

另外,如果我了解您要做什么。我认为您在代码中的逻辑有点不对劲。

您应该在第一次重复中测试listAllDayEvents中的项目。

如果在listAllDayEvents中找到项目,则检查它们是否在第二次重复中匹配。

如果listAllDayEvents中没有项目,则无需进行第二次重复。

只需将 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


注意:给任何想要测试此代码的人。创建两个新日历,每个日历上有几个事件。而不是使用任何可能建立的日历。日历可能非常大,尤其是当它们有一些重复事件或回溯数年时。这意味着您可能整天都在等待脚本完成运行

于 2013-09-17T17:57:56.677 回答