开发者

Get / Set calendar events on iCal (programmatically)

开发者 https://www.devze.com 2022-12-09 22:59 出处:网络
is there any objective C API or object that can give 开发者_运维技巧me access to the iCal and its events?

is there any objective C API or object that can give 开发者_运维技巧me access to the iCal and its events? I need to read the calendar events for a given date and optionally set a new event.

The code is either plain C or objective C (in the GUI version of the program). I'm using xcode on a mac os 10.6.

Sample code is greatly appreciated.


As of 10.8 (Mountain Lion), Calendar Store is deprecated. You should now use Event Kit.


You might find it easier to use iCal's Apple Events scripting interface. If you don't like the idea of using AppleScript directly, there is Apple's Scripting Bridge or, even better, use Appscript for Objective-C, Ruby, or Python. Here's one way to access and modify the events for a given day using py-appscript:

>>> from appscript import *
>>> from datetime import datetime
>>> start_time = datetime(2009,10,26)
>>> end_time = datetime(2009,10,26,23,59,59)
>>> calendar = app('iCal').calendars['Home']
>>> for event in calendar.events[(its.start_date >= start_time).AND(its.start_date <= end_time)]():
...   event_properties = event.properties()
...   print event_properties[k.start_date], event_properties[k.summary]
... 
2009-10-26 18:40:00 <event 1>
2009-10-26 23:38:00 <event 2>
>>> event.summary.set(to='something else')
0

精彩评论

暂无评论...
验证码 换一张
取 消