• 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: Jay Louvion <email@hidden>
  • Date: Tue, 20 Oct 2015 15:34:32 +0200

The error I had seems to be caused by trying to address an iCloud calendar.
If I use a local and very empty calendar, it returns {true, 0.387127041817}

The example would be more use at this point, if I may, by testing it on an iCloud calendar. A pretty full one.

How can the script be modified to address an iCloud calendar named "Jay FM”?

Thanks in advance,

J.

Jay Louvion | Les Studios Casagrande Sàrl
3, rue Müller-Brun
1208 Geneva
T+4122 840 32 72 
F+4122 840 32 71 
BLOG | Facebook | www.studiocasagrande.com


On 20 Oct 2015, at 13:51, Shane Stanley <email@hidden> wrote:

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:

 _______________________________________________
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: Shane Stanley <email@hidden>
    • Re: Calendar scripting
      • From: Shane Stanley <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>)
 >Re: Calendar scripting (From: Shane Stanley <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