• 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: Recurring Reminders/Calendar Events?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recurring Reminders/Calendar Events?


  • Subject: Re: Recurring Reminders/Calendar Events?
  • From: Alex Hall <email@hidden>
  • Date: Wed, 04 Mar 2015 23:21:38 -0500


On Mar 4, 2015, at 9:11 PM, Shane Stanley <email@hidden> wrote:

On 5 Mar 2015, at 11:17 am, Christopher Nebel <email@hidden> wrote:

I’m pretty sure -[EKEventStore eventsMatchingPredicate:] will return occurrences of recurring events in the specified date range.

I could have sworn I tried this and it didn't work, but indeed it does. It looks like the definition of start date that EKEventStore uses is different from that used by Calendar.app, and just what the OP wanted. The question then becomes what Alex wants to do with them.

Indeed, if this works as described, it will be perfect. I'll have to see if I can get date-triggered reminders this way too (I'm not going to bother with location-based ones or those with no triggers). The class reference says I can, so that' will be fun to play with. Thanks a million for this tip… Now, to get it working. See below.

This snippet requires use of a method deprecated in 10.9 because ASObjC can't yet call methods that use blocks (hint, hint), and both the editor and subsequent applets will need access to Calendars in Security & Privacy in System Preferences.

So, Yosemite only then? I'm okay with that. I'd love to support 10.9, but most of my (very small) user base is now on Yosemite, so I'll start here.

When I run this code in an un-saved script file, I get an empty dialog. You said I'd need to gran access to Calendars in System Preferences, but Script Editor doesn't appear in the list of apps that have requested calendar data. In fact, I see no requests at all. I've not yet used ObjC calls in a script, so I'm probably missing an obvious step. My first thought is that I must first save the file as a certain type, but I'm not sure what. Again, I run into the odd lack of traffic on this topic when I search about it. Thanks.

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

-- get the event store
set theEKEventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:1 -- work around enum bug
-- get calendars that can store events
set theCalendars to theEKEventStore's calendarsForEntityType:0 -- work around enum bug. Sigh
-- get the calendars whose title is "Work" or "Home" -- change to suit
set theNSPredicate to current application's NSPredicate's predicateWithFormat_("title IN %@", {"Work", "Home"})
set calsToSearch to theCalendars's filteredArrayUsingPredicate:theNSPredicate
-- create start date and end date for occurences
set startNSDate to current application's NSDate's |date|() -- now
set endNSDate to current application's NSDate's dateWithTimeIntervalSinceNow:(7 * days) -- a week away
-- find matching events
set thePred to theEKEventStore's predicateForEventsWithStartDate:startNSDate endDate:endNSDate calendars:calsToSearch
set theEvents to (theEKEventStore's eventsMatchingPredicate:thePred)
-- get titles and display them
set eventString to (theEvents's valueForKey:"title")'s componentsJoinedByString:", "
display dialog eventString as text


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



--
Have a great day,
Alex Hall
email@hidden

 _______________________________________________
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: Recurring Reminders/Calendar Events?
      • From: Shane Stanley <email@hidden>
References: 
 >Re: Recurring Reminders/Calendar Events? (From: Christopher Nebel <email@hidden>)
 >Re: Recurring Reminders/Calendar Events? (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Recurring Reminders/Calendar Events?
  • Next by Date: Re: Recurring Reminders/Calendar Events?
  • Previous by thread: Re: Recurring Reminders/Calendar Events?
  • Next by thread: Re: Recurring Reminders/Calendar Events?
  • Index(es):
    • Date
    • Thread