py-appscript filter with datetime

200 Views Asked by At

I am trying to use the day field of a datetime property as a filter when selecting events from an iCal calendar.

The following doesn't seem to work (to select all events for the current date):

cal = app("iCal").calendars["myCalender"].get()
cDate = datetime.now()
cEvents = cal.events[its.start_date.day==cDate.day].get()

I get the result: AttributeError: Unknown property, element or command: 'day'

However, this works (for printing the days of any events)...

cal = app("iCal").calendars["myCalender"].get()
for cEvent in cal.events.get():
    print cEvent.start_date.get().day
1

There are 1 best solutions below

1
On

This line

cal.events[its.start_date.day==cDate.day].get()

checks its.start_date.day==cDate.day and returns False or True. As an index, this translates into 0 and 1 and takes one of the first two elements in the cal.events list. Is this what you want?