Thanks for your observation, Stefan. Actually, I am using NSDate in my working application. Seems to produce the same thing.
However, to focus our discussion, I can replicate Ric’s code to illustrate my question.
Well, mostly. Ric, you must have some property statements up above that simplify your code. I added some tell statements so that it would compile and I could follow what’s happening:
on applicationWillFinishLaunching_(aNotification)
set theData to current application's NSMutableArray's alloc()'s init()
--set cal to CalCalendarStore's defaultCalendarStore()
tell current application to ¬
set cal to class "CalCalendarStore"'s defaultCalendarStore()
set homeCal to cal's calendars()
-- set thisYear to NSCalendarDate's |date|()'s yearOfCommonEra()
-- set theStart to NSCalendarDate's dateWithYear_month_day_hour_minute_second_timeZone_(thisYear, 1, 1, 0, 0, 0, missing value)
-- set theEnd to NSCalendarDate's dateWithYear_month_day_hour_minute_second_timeZone_(thisYear, 12, 31, 23, 59, 59, missing value)
tell current application
tell class "NSCalendarDate"
set thisYear to |date|()'s yearOfCommonEra()
set theStart to dateWithYear_month_day_hour_minute_second_timeZone_(thisYear, 1, 1, 0, 0, 0, missing value)
set theEnd to dateWithYear_month_day_hour_minute_second_timeZone_(thisYear, 12, 31, 23, 59, 59, missing value)
end tell
-- set eventPredicate to CalCalendarStore's eventPredicateWithStartDate_endDate_calendars_(theStart, theEnd, homeCal)
tell class "CalCalendarStore" to ¬
set eventPredicate to eventPredicateWithStartDate_endDate_calendars_(theStart, theEnd, homeCal)
end tell
set theEvents to cal's eventsWithPredicate_(eventPredicate)
repeat with anEvent in theEvents
set dict to {eventTitle:anEvent's |title|, theStart:anEvent's startDate}
theData's addObject_(dict)
end repeat
--? setTheData_(theData)
--Here are my observations:
set anEvent to item 1 of theEvents --just to pick one
tell anEvent
log "class of anEvent=" & ¬
|description|() of (|class|() of anEvent)
-->class of anEvent=CalEvent
--startDate and endDate are properties of CalEvent:
log "start date=" & |description|() of |startDate|() & "<"
log "end date =" & |description|() of |endDate|() & "<"
--while notes and title are properties of
--CalEvent's superclass, CalCalendarItem
log "notes=" & notes() & "<"
log "title=" & |title|() & "<"
--when I typed it, the notes line looked like this:
--log "notes=" & |notes|() & "<"
--but the compiler removed the pipes
--I guess because notes isn't a reserved word?
--These worked:
log "start date=" & |description|() of startDate() & "<"
log "start date=" & description of startDate() & "<"
--"description" is pink in the second line
--These did not:
--log "start date=" & |description|() of startDate & "<"
-->The variable startDate is not defined.
--log "title=" & title & "<"
--The variable title is not defined.
--For the following two, the strangest thing happened.
--the compiler did not change the text color,
--which usually indicates a compiliation error,
--but "Build and Run" succeeded, and
--both log statements did work!
--(Notice that the text is still offset.)
log "Two that did not compile:"
log "start date=" & description() of startDate() & "<"
log "title=" & title() & "<"
end tell
end applicationWillFinishLaunching_
Here’s the log from the code above:
I’m going to have to think about this for a while. Perhaps there are rules to cover these situations, but I don’t see them yet. Do you?
–Gil