• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calendar - the big hangover
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calendar - the big hangover


  • Subject: Re: Calendar - the big hangover
  • From: Shane Stanley <email@hidden>
  • Date: Thu, 05 Nov 2015 10:33:38 +1100

On 3 Nov 2015, at 11:33 PM, Jay Louvion <email@hidden> wrote:

Whatever the type of calendar (local or iCloud), the real setback is the amount of events it contains. For example, my calendar, iCloud-based, containing 8000+ events, takes a whopping 155 seconds to create an event.

FWIW, this suggests the problem is, at least in part, the way scripting is implemented in Calendar. Calendar uses Cocoa scripting, which is very simple to implement. The basic way it handles inserting a new item in a collection is relatively slow, although fast enough for modest collections. From the relevant documents: "for an insertion or removal, it must get the value array, make a mutable copy of it, mutate the copy, and then set it again. This can be slow". 

If you want to give them a nudge in the right direction, you could suggest they implement collection mutation methods. In this case, probably something like insertObject:inEventsForScriptingAtIndex: and reomveObjectFromEventsForScriptingAtIndex:.

Meanwhile the speediest solution is probably to use EventKit directly. For example, since you know the UID, you could use this for deletion:

use scripting additions
use framework "Foundation"
use framework "EventKit"

set theID to "374F621E-8B76-4082-8ED8-C8CECD5C6E5B"
set calTitle to "Home"
its deletEventWithID:theID inCalName:calTitle

on deletEventWithID:theID inCalName:calTitle
-- create event store and get the OK to access Calendars
set theEKEventStore to current application's EKEventStore's alloc()'s init()
theEKEventStore's requestAccessToEntityType:0 completion:(missing value)


-- check if app has access; this will still occur the first time you OK authorization
set authorizationStatus to current application's EKEventStore's authorizationStatusForEntityType:0 -- work around enum bug
if authorizationStatus is not 3 then
display dialog "Access must be given in System Preferences" & linefeed & "-> Security & Privacy first." buttons {"OK"} default button 1
tell application "System Preferences"
activate
tell pane id "com.apple.preference.security" to reveal anchor "Privacy"
end tell
error number -128
end if


-- get events matching ID
set theEvents to (theEKEventStore's calendarItemsWithExternalIdentifier:theID)
-- Calendars.app uses non-uique IDs, so there may be more than one; in this case filter by calendar
if (count of theEvents) > 1 then
set theNSPredicate to current application's NSPredicate's predicateWithFormat_("calendar.title == %@", calTitle)
set theEvents to theEvents's filteredArrayUsingPredicate:theNSPredicate
end if
-- do the deletion(s)
repeat with anEvent in theEvents
(theEKEventStore's removeEvent:anEvent span:1 commit:true |error|:(missing value))
end repeat
end deletEventWithID:inCalName:

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Calendar - the big hangover
      • From: Shane Stanley <email@hidden>
References: 
 >Calendar - the big hangover (From: Jay Louvion <email@hidden>)

  • Prev by Date: Re: Calendar - the big hangover
  • Next by Date: Re: Calendar - the big hangover
  • Previous by thread: Calendar - the big hangover
  • Next by thread: Re: Calendar - the big hangover
  • Index(es):
    • Date
    • Thread