iCal - Arrange Calanders

I havent been able to find any documentation on organizing calendars in iCal.
I want to add a blip in my script to alphabetize all my calendars…

any ideas?

Hi bluenote,

try this

tell application "iCal" to set nameList to name of calendars
Qsort(nameList, 1, count nameList)
repeat with i in nameList
	tell application "iCal" to move (1st calendar whose name is i) to end of calendars
end repeat

to Qsort(array, leftEnd, rightEnd) -- Hoare's QuickSort Algorithm
	script a
		property L : array
	end script
	set {i, j} to {leftEnd, rightEnd}
	set v to item ((leftEnd + rightEnd) div 2) of a's L -- pivot in the middle
	repeat while (j > i)
		repeat while (item i of a's L < v)
			set i to i + 1
		end repeat
		repeat while (item j of a's L > v)
			set j to j - 1
		end repeat
		if (not i > j) then
			tell a's L to set {item i, item j} to {item j, item i} -- swap
			set {i, j} to {i + 1, j - 1}
		end if
	end repeat
	if (leftEnd < j) then Qsort(a's L, leftEnd, j)
	if (rightEnd > i) then Qsort(a's L, i, rightEnd)
end Qsort

that works good…but its very slow…as it moves each file to end and then reorders based on next file…

is there any other way to do this so that on Make new Calendar…it can automatically put it in the right spot?

AFAIK no
I know, this solution is quite slow but it works

I agree with Stefan; the slowness seems to come from iCal, not the sorting routine. I tried it with my favorite sort, the bubblesort, and although the sorting was nearly instantaneous (with 10 calendars), the repeat loop telling iCal to re-order the calendars took just over a second. I did not time it, but with the same 10 calendars, using my in the iCal repeat seemed to go a bit quicker:

tell application "iCal" to set nameList to name of calendars
bubblesort(nameList)
repeat with i in my nameList
	tell application "iCal" to move (1st calendar whose name is i) to end of calendars
end repeat

on bubblesort(array)
	repeat with i from length of array to 2 by -1 --> go backwards
		repeat with j from 1 to i - 1 --> go forwards
			tell array
				if item j > item (j + 1) then
					set {item j, item (j + 1)} to {item (j + 1), item j} -- swap
				end if
			end tell
		end repeat
	end repeat
	return array
end bubblesort