weekly recurring event with given days


I am seeing an unexpected behaviour when creating weekly recurring event with specific days. For example:

set cal_properties to {summary:"testing summary", location:" Location of the Event", url:"www.blackberry.com", recurrence:"FREQ=WEEKLY;BYDAY=MO,FR"}
			set event_1 to make new event at end with properties cal_properties

In this case what it does is, it creates one event for my current date and then it creates recurring event on Monday and Friday. Say today is Thursday, and what it will do is create an event for today with recurring properties of ’ FREQ=WEEKLY;BYDAY=MO,FR" [even though today is not MO or FR].

If however I were to create this manually, iCal automatically removes the first event that is created today.

Any idea how I can avoid creating this one event?


iCal (when done manually) does not remove the event, it hides it. All recurring events are stored on the day they are created and future instances are then computed on the fly. Unfortunately, iCal’s AppleScript Dictionary doesn’t expose any way to hide an event among its properties. For that reason it’s best to script new recurring events on the future date of their first occurrence.

Actually, that appears not to be strictly true. Whereas iCals 1.5.5 and 2.0.5 kept the original entry date and only used the recurrence days for the recurrences, iCal 4.0.2 actually shifts the event’s start date, if necessary, to the next due specified recurrence day. If the recurrence interval’s greater than 1 and the next recurrence weekday is on or after the specified or default week start, the start date is further shifted by the relevant number of weeks. However, the AppleScript implementation hasn’t changed to mirror this ” and a good job too, I say, as the new behaviour’s utterly crass.

If it really is necessary to mimic the new behaviour in AppleScript, this might help with the setup:

-- Given a start date, an end date, a list of weekdays (which can be left empty), a recurrence interval, and a week-start weekday, return the start date and end date of the first due instance of a "weekly" recurrence and the recurrence specification string.

on prepareWeeklyRecurrence(startDate, endDate, wkDays, interval, wkSt)
	set byDays to {"SU", "MO", "TU", "WE", "TH", "FR", "SA"}
	set wkSt to wkSt as integer
	if (wkDays is {}) then
		set bydayStr to ""
		repeat with w in wkDays
			set w's contents to w as integer
		end repeat
		set w to startDate's weekday as integer
		set d to 0
		repeat until (w is in wkDays)
			set w to w mod 7 + 1
			set d to d + days
			if (w is wkSt) then set d to d + (interval - 1) * weeks
		end repeat
		set startDate to startDate + d
		set endDate to endDate + d
		set bydayStr to "BYDAY="
		repeat with w in wkDays
			set bydayStr to bydayStr & item w of byDays & ","
		end repeat
		set bydayStr to text 1 thru -2 of bydayStr & ";"
	end if
	set recurrence to "FREQ=WEEKLY;INTERVAL=" & interval & ";" & bydayStr & "WKST=" & item wkSt of byDays
	return {startDate, endDate, recurrence}
end prepareWeeklyRecurrence

set startDate to (current date) -- (Result below for 7th May 2010.)
set time of startDate to 14 * hours
set endDate to startDate + 90 * minutes
set wkDays to {Monday, Thursday}
set interval to 1
set wkSt to Monday
prepareWeeklyRecurrence(startDate, endDate, wkDays, interval, wkSt)
--> {date "Monday 10 May 2010 14:00:00", date "Monday 10 May 2010 15:30:00", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TH;WKST=MO"}

Thanks again NG:)

I will be trying your code on Monday and let you know! I am done for this week and have a lot of renovation work to do for my house :slight_smile:

Thanks to both you and Adam for all the help!

Have a good weekend!


Sorry for the delayed reply.

It worked “perfectly”. Can’t thank you enough for all your time Nigel.