Tuesday, September 21, 2021

#1 2021-09-11 06:01:26 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 880

NSCalendar, EKEventStore, predicateForEventsWithStartDate

I was doing some research on Shane Stanley code ASObjC with Calendar.

I add some valueForKey to output more information specially the summary key is very useful.

To use this ASObjC code you need to change the property title and type to your calendar.

Applescript:

use AppleScript version "2.4"
use framework "Foundation"
use framework "EventKit"
use scripting additions

property calendarTitle : {"bookinginfo"}

-- Calendar types: : Local = 0, CalDAV/iCloud = 1, Exchange = 2, Subscription = 3, Birthday = 4
property calendarType : {1}

set theDate to current application's NSDate's |date|()
set currentDate to current application's NSCalendar's currentCalendar()'s dateBySettingHour:9 minute:0 |second|:0 ofDate:theDate options:0
-- set the interval to 7 days
set endDate to currentDate's dateByAddingTimeInterval:7 * days

set eventStore to current application's EKEventStore's alloc()'s init()
eventStore's requestAccessToEntityType:0 completion:(missing value)

set authorizationStatus to current application's EKEventStore's authorizationStatusForEntityType:0

set theCalendars to eventStore's calendarsForEntityType:0

set predicate to current application's NSPredicate's predicateWithFormat_("title in %@ and type in %@", calendarTitle, calendarType)
set filteredArray to theCalendars's filteredArrayUsingPredicate:predicate
log (filteredArray's valueForKey:"description") as list
if (count of filteredArray) < 1 then error "No calendar find..."

set predicateEvents to eventStore's predicateForEventsWithStartDate:currentDate endDate:endDate calendars:filteredArray
set theEvents to (eventStore's eventsMatchingPredicate:predicateEvents)

set theEvents to theEvents's sortedArrayUsingSelector:"compareStartDateWithEvent:"

-- CalendarEvent class
log (theEvents's |description|()) as string
log (theEvents's valueForKey:"title") as list
log (theEvents's valueForKey:"startDate") as list
log (theEvents's valueForKey:"location") as list
log (theEvents's valueForKey:"notes") as list
log ((theEvents's valueForKey:"URL")'s valueForKey:"absoluteString") as list
log (theEvents's valueForKey:"attachments") as list

log (theEvents's valueForKey:"endDate") as list
log (theEvents's valueForKey:"status") as list
log (theEvents's valueForKey:"summary") as list


if you are the expert, who will you call if its not your imagination.


Filed under: EKEventStore, NSCalendar

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)