grahl/ch

Bulk generating calendar events with Applescript

Sometimes you want to create calendar events which differ in predictable ways such as “Read/do chapter/session/workout x”.

A trivial problem for a programmer but basically impossible with the stock macOS calendar or third-party tools such as Fantastical as far as I can tell. They can have complex recurrence rules but all deviations per event are a manual process it seems.

So here is an Applescript script I quickly googled together for your convenience to create thirty events each containing an integer reference. Adjust as necessary.

tell application "Calendar"
	activate
	--- date() uses your localized date formatting.
	set theCurrentDate to date ("17.12.2016 09:00")
	set i to 1
	repeat while i < 31
		tell calendar "Home"
			make new event at end with properties {description:"", summary:"My task - Day " & i, location:"", start date:theCurrentDate, end date:theCurrentDate + 60 * minutes}
		end tell
		set i to i + 1
		set theCurrentDate to theCurrentDate + (1 * days)
	end repeat
	reload calendars
end tell

The script has obvious limitations with the hardcoded values it contains. A more flexible solution would use dialogs to ascertain the number of events, starting date, calendar to use, or event details.

I’m just content I don’t have to keep adding individual events by hand to get this done.