Deleting very old iCal items with Automator

So I’m working with a client who has iCal items (imported from Palm Desktop) that go back to 1998 or so. Since iCal doesn’t offer a function that I can see to delete, say, all items before a certain date, I wrote a workflow that worked as follows:

Find all items on X calendar before 1999 → Ask for confirmation → Delete selected items

Which worked fine on my test calendar, but when presented with the working calendar (which had about 5 items per day every day of the year), it balked, churned for a bit then crashed. What I assume happened was that Automator spooled all of the found items into RAM, and when that got full, it crashed and OS X shut it down.

I tried solving this by breaking it down year-by-year, but I still ran into the same issue. Is there a way around this that y’all know?

Thanks,

Charles

Hi,

what’s about a plain AppleScript, the script considers only events without any recurrence.
Change the properties to the range of years, in this example the range from Jan 1, 2002 until Dec 31, 2003

property startYear : 2002
property endYear : 2003

tell application "iCal" to set N to name of calendars whose writable is true
set theCal to choose from list N with prompt "Choose a calendar"
if theCal is false then return
set theCal to item 1 of theCal
set uidList to {}
tell application "iCal"
	tell calendar theCal
		repeat with theEvent in (get events)
			set sd to start date of theEvent
			if year of sd > (startYear - 1) and year of sd < (endYear + 1) and recurrence of theEvent is "" then
				set end of uidList to uid of theEvent
			end if
		end repeat
	end tell
	if (count uidList) > 0 then
		display dialog "Delete " & (count uidList) & " events of calendar " & theCal & " permanently?" buttons {"Cancel", "Yes"}
		if button returned of the result is "Yes" then
			repeat with x from 1 to count of uidList
				delete (some event of calendar theCal whose uid is item x of uidList)
			end repeat
		end if
	else
		display dialog "Nothing to delete" buttons {"OK"} default button 1
	end if
end tell