【问题标题】:Deletion of Apple Calendar event though Applescript通过 Applescript 删除 Apple 日历事件
【发布时间】:2018-04-11 14:44:52
【问题描述】:

我正在尝试通过 Applescript 删除 Apple 内置日历应用程序中的特定日历事件。我可以找到该事件,但无法使用我找到的方法将其删除。

以下脚本定位名为Test Event 的事件并将其显示在日历应用程序中。它工作正常。

set theStarttime to date "Wednesday, 18 April 2018 at 17.00.00"
set theEndtime to date "Wednesday, 18 April 2018 at 18.00.00"
set theSummary to "Test Event"

tell application "Calendar" to tell calendar "Privat"
    set theEventList to every event where its start date is greater than or equal to theStarttime
        and end date is less than or equal to theEndtime and summary is equal to theSummary
    set theEvent to first item of theEventList
    show theEvent
end tell

如果我尝试删除事件而不是通过将行 show theEvent 更改为 delete theEvent 来显示它,则脚本执行后该事件仍在日历应用程序中。但是,它似乎以某种方式被删除了,因为脚本无法再找到该事件。

如何从我的日历中删除活动?

【问题讨论】:

    标签: calendar applescript


    【解决方案1】:

    delete 是正确的,但你必须save 日历。我添加了一个if 条件,它可以避免在找不到事件时出错。

    tell application "Calendar"
        tell calendar "Privat"
            set theEventList to every event where its start date ≥ theStarttime and end date ≤ theEndtime and summary is equal to theSummary
            if theEventList is not {} then
                set theEvent to first item of theEventList
                delete theEvent
            end if
        end tell
        save
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      相关资源
      最近更新 更多