Applescript和iCal互动

noz*_*cle 3 icalendar applescript

我正在尝试编写一个AppleScript来查询iCal,并在任何日历中查找我在给定日期获得的所有事件.

我首先编写了一个简单的脚本,它可以对给定日历中的每个事件执行简单的操作:

tell application "iCal"
  tell calendar "Reuniones"
    set the_events to every event
    repeat with an_event in the_events
        -- do something with every event
        set value to summary of an_event
    end repeat
   end tell
end tell
Run Code Online (Sandbox Code Playgroud)

但是,这个简单的脚本需要花费很多时间来执行(几秒钟),即使我在循环中没有做任何复杂的事情.我担心真正的脚本会花费很多时间来执行.

我对Applescript不太熟悉,因此我想我正在做一些具有严重性能影响的傻事.

任何人都可以解释为什么这需要那么多来执行?任何人都可以建议改进我的代码吗?我现在要开始检查事件的日期,循环中有一个条件.我怀疑必须有一种方法来搜索带有日期的事件(比如Automator动作),但是我无法找到一种"原生"方式来做到这一点....

编辑:我正在使用Mac OS X Tiger(10.4).新版本的iCal可能改进了可用的操作库.

Dun*_*gor 5

我今天一直在努力解决这个问题,发现你可以按日期过滤(至少在Snow Leopard上).所以

tell application "iCal"
    set out to ""
    set todaysDate to current date
    set time of todaysDate to 0
    repeat with c in (every calendar)
        set theEvents to (every event of c whose start date ? todaysDate)
        repeat with current_event in theEvents
            set out to out & summary of current_event & "\n"
        end repeat
    end repeat
    return out
end tell
Run Code Online (Sandbox Code Playgroud)

与迭代所有事件相比,将返回所有未来事件的摘要,并且非常快速.