I need help in scripting Calendar. I want to find out if an event exist on a certain date in a certain calendar.
For example. I have a “Vacation” calendar and I want to know if an exist an event on today. i want to use that in my Home Automation system so that I can set up different configurations of my home. I intent to run that script every day in the AM.
I can get the summaries for that calendar, but cannot figure out how to sep through them to find today.
Thanks for amy help.
HI. Here is one way to get today’s events. It uses a whose clause, which should be fine for a calendar with a relatively small number of entries.
set witchingHour to date (get (current date)'s date string) --today's midnight
tell application "Calendar"
tell calendar "Vacation"
(events whose (start date ≥ witchingHour) and (end date ≤ (witchingHour + 1 * days + -1 * minutes)))'s summary
end tell
end tell
Hi Shane, I am not worried about repeating events. However I would like to capture banners, which Am’s script doesn’t. That is something I can work around though, although would be nice to have.
I long ago abandoned using relativized repeating event entries, and I had actually forgotten that feature even existed. I do see your point, if someone uses that feature, and am curious as to your method for getting around the relative dates.
You can use one of my script libraries, either CalendarLib (for 10.9+) or CalendarLib EC (10.11-only). They’re very similar. They use AppleScriptObjC to script the EventKit framework directly, so they not only get around the problem of repeating events, they also remove the need for Calendar.app to be running, and they’re much, much faster.
Access to that side of things is off-limits, unfortunately. But CalendarLib EC does still offer greater speed and the ability to run without launching Calendar.app.