AppleScript的和iCal互动 [英] Applescript and iCal interaction
问题描述
我想写一个AppleScript查询iCal和发现我有给定日期的所有事件,在任何日历。
I'm trying to write an AppleScript to query iCal and find all the events I've got for a given date, in any calendar.
我开始通过编写一个简单的脚本,做一些简单的与每一个事件在给定的日历:
I started by writing a simple script that does something simple with every event in a given calendar:
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
然而,这个简单的脚本是采取了很多时间来执行(几秒钟),即使我没有做任何事情的循环内的复杂。恐怕真正的脚本会真的采取了很多的时间来执行。
However, this simple script is taken a lot of time to execute (a few seconds), even if I'm not doing anything complex inside the loop. I'm afraid that the real script will really take a lot of time to execute.
我不是很熟悉AppleScript的,因此我想象我在做一些愚蠢的有严重的性能问题。
I'm not very familiar with Applescript, and thus I imagine I'm doing something silly that has severe performance implications.
有人能解释我为什么这需要那么多的执行?任何人都可以提出一些提高我的code?现在我要开始检查事件的日期,在循环的条件。我怀疑必须有带有日期搜索事件(如动作的Automator一样)的方式,但我一直没能找到一个原生的方式来做到这一点....
Can anybody explain me why this takes that much to execute? Can anybody suggest something to improve my code? I'm now going to start checking the date of the event, with a condition in the loop. I suspect there must be a way to search for events with a date (like the Automator action does), but I haven't been able to find a "native" way to do so ....
的修改的:我使用的是Mac OS X老虎(10.4)。这是可能的的iCal的新版本已经改善可用操作的库
EDIT: I'm using Mac OS X Tiger (10.4). It is possible that newer versions of iCal have improved the library of operations available.
推荐答案
我一直在努力解决这个今天发现,你可以按日期(至少在雪豹)滤波器。因此,
I've been grappling with this today and found that you can filter by date (at least on Snow Leopard). So
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
将返回所有未来事件的总结,并很快,相比之下,通过所有事件迭代。
will return the summary of all future events, and very quickly, compared to iterating through all events.
这篇关于AppleScript的和iCal互动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!