4

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.

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Uri
  • 1,275
  • 6
  • 17
  • 26

2 Answers2

5

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

andrewrjones
  • 1,801
  • 21
  • 25
1

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')
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • thank you but even tho i like Python and other scripts a lot I can't use that this time. Either C or objective C – Uri Nov 03 '09 at 17:46
  • It should be simple to translate that code to the Objective C version of Appscript. – Ned Deily Nov 03 '09 at 17:54
  • the reason I asked in the 1st place is because I don't even know what objects or API's I need to be able to talk to the calendar store. So, translating that would be a bit difficult if I don't know what functions I need. – Uri Nov 04 '09 at 14:04
  • I'm not sure I understand correctly but, if you want to understand the iCal scripting data model, the standard way to do that - as with any OS X scriptable app - is to introspect the model using the AppleScript Editor (in /Applications/Utilites) Open Dictionary command. But in this case use the tools provided with Appscript (http://appscript.sourceforge.net/tools.html): ASDictionary translates the iCal's data model dictionary into Objective C-appscript syntax and can also automatically generate all the Objective C glue code to access that data model. In any case, good luck. – Ned Deily Nov 04 '09 at 17:51
  • 1
    Using Apple Events has the *big* disadvantage of needing iCal to be launched when accessing it. The Calendar Store is designed exactly to avoid doing this. – Mike Abdullah Nov 05 '09 at 14:57
  • It's true iCal has to be running when using Apple Events. That may be a disadvantage depending on your application. All in all, using the Calendar Store framework is a more robust solution but, for many applications, using Apple Events is perfectly adequate, plus the approach generalizes to most other OS X scriptable applications - even if there isn't a "standalone" API alternative. – Ned Deily Nov 05 '09 at 18:17
  • Thanks all, but PLEASE i don't want a script. I clearly wrote that I need to code this in C or objective C. I don't understand why this isn't clear. – Uri Nov 05 '09 at 22:25
  • and no, I don't want to try this. and no, I don't want to translate this. Thanks for the answer but it's not what i am looking for. – Uri Nov 05 '09 at 22:26