• 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 scripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calendar scripting


  • Subject: Re: Calendar scripting
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 20 Oct 2015 22:51:53 +1100

On 20 Oct 2015, at 9:00 PM, Jay Louvion <email@hidden> wrote:

PS - strange thing is this only “half-broke” when we moved to Yosemite or El Capitan. The only machine running 10.7 does a fine job creating and deleting events in multiple calendars. Same calendars, btw. Everything is synced via iCloud.

So use the code you posted to make a new event, and then run this to delete it (requires Yosemite or El Capitan). Tell us how long it takes to run (the result).

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

set startDate to current application's NSDate's |date|()
set theResult to its deleteEventFromCalendar:"Work" eventLocation:"Using applescript"
return {theResult, -(startDate's timeIntervalSinceNow())}

on deleteEventFromCalendar:calName eventLocation:theLocation
-- 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 calendars that can store events
set theCalendars to theEKEventStore's calendarsForEntityType:0
-- get the calendars whose title is in the passed list of names
set theNSPredicate to current application's NSPredicate's predicateWithFormat_("title == %@", calName)
set calsToSearch to theCalendars's filteredArrayUsingPredicate:theNSPredicate


-- create start date and end date for occurences
set nowDate to current application's NSDate's |date|()
-- get start of day then end of day
set startNSDate to current application's NSCalendar's currentCalendar()'s startOfDayForDate:nowDate
set endNSDate to current application's NSDate's dateWithTimeInterval:(1 * days - 1) sinceDate:startNSDate


-- find matching events
set thePred to theEKEventStore's predicateForEventsWithStartDate:startNSDate endDate:endNSDate calendars:calsToSearch
set theEvents to (theEKEventStore's eventsMatchingPredicate:thePred)
repeat with i from 1 to count of theEvents
if ((item i of theEvents)'s location()'s isEqualToString:theLocation) as boolean then
(theEKEventStore's removeEvent:(item i of theEvents) span:1 commit:true |error|:(reference))
return true
exit repeat
end if
end repeat
return false
end deleteEventFromCalendar:eventLocation:

-- 
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 scripting
      • From: Jay Louvion <email@hidden>
    • Re: Calendar scripting
      • From: Christopher Stone <email@hidden>
References: 
 >Calendar scripting (From: Jay Louvion <email@hidden>)
 >Re: Calendar scripting (From: Shane Stanley <email@hidden>)
 >Re: Calendar scripting (From: Jay Louvion <email@hidden>)

  • Prev by Date: Re: Calendar scripting
  • Next by Date: Re: Calendar scripting
  • Previous by thread: Re: Calendar scripting
  • Next by thread: Re: Calendar scripting
  • Index(es):
    • Date
    • Thread