[Pythonmac-SIG] Scripting iCal :: getting the events of the day?

Paul Berkowitz berkowit at silcom.com
Wed Jul 7 04:56:18 CEST 2004


On 7/6/04 6:27 PM, "Israel C. Evans" <israel at sandlotgames.com> wrote:

> I've recently, under the direction of the wonderful suggestion I received on
> this list, begun to use appscript to script iCal.  One of my main goals with
> doing so is to extract all the events that happen to occur on any given day.
> This is turning out to be quite difficult for it seems that the osa dictionary
> for iCal offers no methods for retrieving said events.  Each event has
> properties which include useful things like startdate and enddate as well as
> recur which has the ical string of recurrence rules.  It's easy to get an
> event based on the start date or end date, but parsing the diverse and sundry
> possible combinations of recurrence rules leaves me where I left attempting to
> parse the .ics manually... lost in the forest.
> 
> I've been able to activate iCal, move to a particular day and change the view
> to day view so that I can see the events of that day.   If there was a way to
> select the events "visually" (i.e. select all events visible in current view),
> then I might be onto something but so far, I haven't found any way to do that.
> 
> 
> If any of you wise and wonderful people out there have any tips, hints or rude
> limericks that could help me figure this out, I would be most grateful.

It's not so ornate as all that. iCal stores its events in separate
calendars, so you have to search per calendar. It implements 'whose clauses'
for quick searching. Here's how to do it in pure AppleScript, which doesn't
really belong on this list. You should join the AppleScript-Users mailing
list, on Apple's website.

set today to (current date) --or date "8/1/2004"
set time of today to 0 -- midnight, if not
set tomorrow to today + (1 * days)
tell application "iCal"
    set dayEvents to {}
    repeat with c in (every calendar)
        set end of dayEvents to (every event of c whose start date „ today
and start date < tomorrow)
    end repeat
end tell
return dayEvents


[1] The long line includes a symbol made by holding down Option key and
pressing ".", meaning 'greater than or equal to'. If this mailing list
should happen to display it incorrectly, you'll know what to do. It's like
">" but with option, not shift, key held.

[2] The result will be a list of iCal event objects. Perhaps you can turn
that into a Python array if Python can deal with these objects. Otherwise
you'll need to parse each one when you get it, to include a list of
primitive types (strings, booleans and dates) which you can manage in
Python. Write back if you need this. Or just do the whole thing in
AppleScript and ask on the AppleScript-Users list.

-- 
Paul Berkowitz

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20040706/a27d74d0/attachment.html


More information about the Pythonmac-SIG mailing list