Calculate business (work) days, exclude national / regional holidays

I need to determine the date from now, adding 10 working days. Working days are, in my case, Mon-Fri, plus any regional holidays (christmas etc.). My Calendar app has included a calendar that defines those holidays.

Now I wonder if I can script Calendar.app to calculate these date offsets. I’d first take the start date (e.g. today’s) and add a day, checking whether it’s Mon-Fri. If so, I count these days until my limit has been reached. I also have to check whether it’s a holiday. So I’d get the holidays calender and see if that day contains an event on that day. But how do I do that?

I’ve looked at its dictionary, and browsed it with Script Debugger.

I found that when I run this code:

tell application id "com.apple.iCal" -- Calendar
	tell its calendar "National Holidays"
		tell its event 2
			start date
		end tell
	end tell
end tell

Then it takes SEVERAL SECONDS to get my the result. The particular calendar has 800 entries (holidays for several years in advance). This is on 10.12.6. Did not try later macOS versions, yet.

Can this be optimized? Or is this a known issue with the extreme slowness here?

Scripting Calendar is indeed very slow.

Have a look at CalendarLib EC v1.1.3 on https://www.macosxautomation.com/applescript/apps/Script_Libs.html.

The library uses the EventKit framework which is much more efficient

Ah, thanks.

I have solved my task differently now, though: As the app that requires this is written in Xojo, I found that there’s an MBS plugin for accessing the classic Calendar API, and that is fast, and even lets me query all Events within a date range, which is perfect for my needs.