« CheatSheet - an app for showing available key commands | Main | Enabling user web sites on Mac OS X Server »
Wednesday
Jun202012

Creating a countdown calendar in iCal (or BusyCal etc)

I needed to create a custom calendar for someone with a single event per day telling the number of days remaining until a particular date.  AppleScript made this easy:

tell application "iCal"
	tell calendar "Studio Countdown"
		set theDate to date "Thursday, October 4, 2012 12:00:00 AM"
		set daysUntilShow to 1
		repeat while theDate is greater than or equal to ((current date) - (1 * days))
			make new event at end with properties {description:"", summary:"T-" & (daysUntilShow as string), location:"", start date:theDate, allday event:true}
			set theDate to theDate - (1 * days)
			set daysUntilShow to daysUntilShow + 1
		end repeat
	end tell
end tell