Scripting Bridge > iCal, Kalender anlegen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Scripting Bridge > iCal, Kalender anlegen

    Hallo,

    also ich bin gerade ratlos…

    Ich füge iCal einen neuen Kalender hinzu und der Zeiger ist auf einen anderen Kalender gerichtet.
    D.h. wenn ich Kalender A anlege, dann bekomme ich mal den Zeiger auf B, C etc. - total dubios.

    Code, siehe unten…
    Sieht da jemand einen Fehler?

    Viele Grüße


    C-Quellcode

    1. +(APCalendarCalendar*)wc_createCalendarWithName:(NSString*)name
    2. {
    3. // …
    4. if([name length] < 1)
    5. {
    6. return nil;
    7. }
    8. // …
    9. APCalendarApplication *application = [SBApplication applicationWithBundleIdentifier:@"com.apple.iCal"];
    10. if(application == nil)
    11. {
    12. return nil;
    13. }
    14. // …
    15. SBElementArray *array = [application calendars];
    16. if(array == nil)
    17. {
    18. return nil;
    19. }
    20. // …
    21. NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
    22. if(mutableDictionary == nil)
    23. {
    24. return nil;
    25. }
    26. // …
    27. // tell application "Calendar" to delete (every calendar whose name begins with "tmpTEST")
    28. // …
    29. [mutableDictionary wc_setObject:@"tmpTEST" // TODO
    30. forKey:@"name"];
    31. // …
    32. Class class = [application classForScriptingClass:@"calendar"];
    33. if(class == NULL)
    34. {
    35. return nil;
    36. }
    37. APCalendarCalendar *calendar = [[[class alloc] initWithProperties:mutableDictionary] autorelease];
    38. if(calendar == nil)
    39. {
    40. return nil;
    41. }
    42. // …
    43. [array addObject:calendar];
    44. // …
    45. return calendar;
    46. // …
    47. }
    Alles anzeigen

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von little_pixel ()

  • Das funktioniert wunderbar…

    Viele Grüße


    C-Quellcode

    1. +(EKSource*)wc_localSource
    2. {
    3. // …
    4. EKEventStore *store = [[[EKEventStore alloc] init] autorelease];
    5. if(store == nil)
    6. {
    7. return nil;
    8. }
    9. // …
    10. NSArray *array = [store sources];
    11. if([array count] < 1)
    12. {
    13. return nil;
    14. }
    15. // …
    16. for(EKSource *nSource in array)
    17. {
    18. // …
    19. if([nSource sourceType] != EKSourceTypeLocal)
    20. {
    21. continue;
    22. }
    23. // …
    24. return nSource;
    25. // …
    26. }
    27. // …
    28. return nil;
    29. // …
    30. }
    31. +(EKCalendar*)wc_createCalendarWithName:(NSString*)name
    32. {
    33. // …
    34. if([name length] < 1)
    35. {
    36. return nil;
    37. }
    38. // …
    39. EKEventStore *store = [[[EKEventStore alloc] init] autorelease];
    40. if(store == nil)
    41. {
    42. return nil;
    43. }
    44. // …
    45. EKSource *source = [self wc_localSource];
    46. if(source == nil)
    47. {
    48. return nil;
    49. }
    50. // …
    51. EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent
    52. eventStore:store];
    53. if(calendar == nil)
    54. {
    55. return nil;
    56. }
    57. // …
    58. [calendar setTitle:name];
    59. [calendar setSource:source];
    60. // …
    61. NSError *error = nil;
    62. // …
    63. [store saveCalendar:calendar
    64. commit:YES
    65. error:&error];
    66. if(error != nil)
    67. {
    68. return nil;
    69. }
    70. // …
    71. return calendar;
    72. // …
    73. }
    Alles anzeigen