use scripting additions
use framework "EventKit"
use framework "Foundation"
set eventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:(current application's EKEntityMaskReminder)
tell application "Reminders"
set reminderItem to my EKReminder(eventStore, reminder 1)
set reminderArray to my EKReminderArray(eventStore, id of reminders whose completed = false, {current application's NSSortDescriptor's sortDescriptorWithKey:"self.title" ascending:true})
end tell
my reminderInReminders(reminderItem)
my reminderListInReminders(reminderArray)
on EKReminder(eventStore, aReminder)
--require framework: EventKit, Foundation
return item 1 of my EKReminderArray(eventStore, {aReminder}, {})
end EKReminder
on EKReminderArray(eventStore, reminderList as list, sortDescriptors as list)
--require framework: EventKit, Foundation
set reminderArray to current application's NSMutableArray's arrayWithCapacity:(count reminderList)
repeat with aReminder in reminderList
tell application "Reminders"
if class of aReminder = reminder then
set reminderIdentifier to (current application's NSURL's URLWithString:(id of aReminder))'s |host|
else if aReminder starts with "x-apple-reminder://" then
set reminderIdentifier to (current application's NSURL's URLWithString:aReminder)'s |host|
else
set reminderIdentifier to aReminder as text
end if
end tell
set reminder to (eventStore's calendarItemWithIdentifier:reminderIdentifier)
(reminderArray's addObject:reminder)
end repeat
return reminderArray's sortedArrayUsingDescriptors:sortDescriptors
end EKReminderArray
on reminderInReminders(reminder)
--require framework: EventKit, Foundation
return item 1 of my reminderListInReminders({reminder})
end reminderInReminders
on reminderListInReminders(reminderArray as list)
--require framework: EventKit, Foundation
set reminderList to {}
repeat with reminder in reminderArray
set reminderID to ((current application's NSString's stringWithString:"x-apple-reminder://")'s stringByAppendingString:(reminder's calendarItemIdentifier)) as text
tell application "Reminders"
set end of reminderList to reminder id reminderID
end tell
end repeat
return reminderList
end reminderListInReminders