I’m having a bit of trouble trying to access the URL property of a calendar event. I’ve successfully been able to create and delete calendar events, and also (using EKEvent) access/edit other properties of these events , such as notes, startdate, etc. but it seems there is no URL property in EKEvent. There is one, however, in EKCalendarItem. Problem is, I am getting an unrecognized selector error when trying to pass an event’s identifier to EKCalendarItem. Here’s the code:
set eventStore to current application's EKEventStore's (alloc()'s initWithAccessToEntityTypes:(current application's EKEntityMaskEvent))
set allCalendars to eventStore's calendarsForEntityType:(current application's EKEntityTypeEvent)
repeat with aCalendar in allCalendars
set aCalendarName to aCalendar's defaultOrganizerNameForNewItems()
if (aCalendarName as text) is "Test Calendar" then
set testCalendar to aCalendar
exit repeat
end if
end repeat
set endDate to current application's NSDate's |date|()
set startDate to endDate's dateByAddingTimeInterval:-31536000
set calendarArray to {testCalendar}
set aPredicate to eventStore's predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray
set allEvents to eventStore's eventsMatchingPredicate:aPredicate
repeat with anEvent in allEvents
-- Here is where I want to get the URL of anEvent, but can't get past setting up the EKCalendarItem "calendarItem"
-- The class reference for EKCalendarItem indicates to use calendarItemWithIdentifier to look up the item by this value, but obviously I'm missing something here.
-- The following results in an unrecognized selector error:
set anIdentifier to (eventIdentifier of anEvent)
set calendarItem to (current application's EKCalendarItem's calendarItemWithIdentifier:anIdentifier)
-- Next lines will hopefully be something simple like:
-- set URL of calendarItem to aURL --(where aURL is a NSURL)
end repeat
Thanks for the response and suggestions Stefan! I can retrieve the URL using the example you provided, but can’t seem to write a new one to the event. Shouldn’t |URL|() be expecting a NSURL? The error I’m getting (and I’m nowhere near being an expert on interpreting error messages) suggests to me that I am sending the wrong object type to |URL|()
tell current application's class "NSURL" to set aURL to its URLWithString:"http://www.apple.com"
-- both attempts below fail :(
-- Error: Can't set «class ocid» id «data optr0000000000C8660080600000» to «class ocid» id «data optr000000004082460000600000». (error -10006)
set |URL|() of anEvent to aURL
set anEvent's |URL|() to aURL
For other properties in calendar events, I have been doing things like the following (and thus is what I tried with |URL|() ):
set title of anEvent to "Test Event"
set notes of anEvent to "Test Notes"
set calendar of anEvent to aCalendar
But perhaps setTitle ,setNotes, setCalendar would be functional too? I couldn’t find any documentation with good examples of working with these properties…