NSCalendarDate, LRCalendarView and Call Method questions

I’m attempting to integrate LRCalendarView into my application. While reading the documentation, I observed that it needs to be passed an NSCalendarDate. Unfortunately, there doesn’t seem to be a way to get such a thing in Applescript Studio, which seems to only handle NSDates. If anyone knows of a way to transform an NSDate in MM/DD/YY format into a NSCalendarDate in Applescript Studio, I would be greatly appreciative. Even better would be working code to add events to an LRCalendarView, although I’m fairly sure I’ve got that under control if I can get the NSCalendarDate. For what it’s worth, I’ve tried initWithString:calendarFormat: and dateWithString:calendarFormat:, but neither seem to have worked, presumably due to errors in my call method code.

Hi gonfunko,

I’d suggest passing the date as string instead - you can achieve this with a little modification/addition of/to Logan’s Class:

in ‘LRCalendarView.h’ add:

  • (void)addObject:(id)object
    withTitle:(NSString *)title
    atCalendarDate:(NSCalendarDate *)date;
    - (void)addObject:(id)object
    withTitle:(NSString *)title
    atDate:(NSString *)dateString;
  • (void)deselectAll;
  • (void)deselectAllExceptForDate:(NSCalendarDate *)date;
  • (void)removeAllObjects;

and in ‘LRCalendarView.m’ add this anywhere (outside of other methods definitions of course :wink: ):

- (void)addObject:(id)object
withTitle:(NSString *)title
atDate:(NSString *)dateString{
[self addObject:object
atCalendarDate:[self dateWithoutTime:[NSCalendarDate dateWithNaturalLanguageString:dateString]]];

Now you can call it like this:

	tell view "cv" of window "main"
		call method "addObject:withTitle:atDate:" of it with parameters {null, "Test", (get current date) as string}
	end tell

You can even pass strings like ‘Tomorrow’ or ‘Today’ …

Hope that helps,


Thanks a ton - it works great!