How to sort this?

I would like a return delimited list sorted by name.


set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return} -- save delimiter value and set the new one
tell application "Finder"
	set theList to "1,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "3,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "1,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "3,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "1,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "CompareStefan.scpt,Thursday, 7 May 2009 12:31:57 PM,Thursday, 7 May 2009 12:31:57 PM,2458,osas,ToyS" & return & "SleepX.cache,Tuesday, 5 May 2009 10:34:35 PM,Tuesday, 5 May 2009 10:34:55 PM,169,TEXT,missing value" & return & "CompareStefan.scpt,Thursday, 7 May 2009 12:31:57 PM,Thursday, 7 May 2009 12:31:57 PM,2458,osas,ToyS" & return & "SleepX.cache,Tuesday, 5 May 2009 10:34:35 PM,Tuesday, 5 May 2009 10:34:55 PM,169,TEXT,missing value"
	set sortedList to (sort theList by name)
end tell
set AppleScript's text item delimiters to ASTID
return theList

No need to speak to the Finder.


on run
	set theList to "1,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "3,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "1,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "3,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "1,Thursday, 7 May 2009 9:55:05 PM,Thursday, 7 May 2009 9:56:33 PM,779,TEXT,ttxt" & return & "CompareStefan.scpt,Thursday, 7 May 2009 12:31:57 PM,Thursday, 7 May 2009 12:31:57 PM,2458,osas,ToyS" & return & "SleepX.cache,Tuesday, 5 May 2009 10:34:35 PM,Tuesday, 5 May 2009 10:34:55 PM,169,TEXT,missing value" & return & "CompareStefan.scpt,Thursday, 7 May 2009 12:31:57 PM,Thursday, 7 May 2009 12:31:57 PM,2458,osas,ToyS" & return & "SleepX.cache,Tuesday, 5 May 2009 10:34:35 PM,Tuesday, 5 May 2009 10:34:55 PM,169,TEXT,missing value"
	
	set newList to my recolle(my sort_list(paragraphs of theList), return)
end run

on sort_list(unsortedList)
	set AppleScript's text item delimiters to (ASCII character 10)
	set sortedList to paragraphs of (do shell script "echo " & quoted form of (unsortedList as string) & "| sort  -d -f")
	set AppleScript's text item delimiters to ""
	return sortedList
end sort_list

on recolle(l, d)
	local t
	set AppleScript's text item delimiters to d
	set t to l as text
	set AppleScript's text item delimiters to ""
	return t
end recolle

Thanks to Mark J. Reed for the sort handler.

Yvan KOENIG (from FRANCE dimanche 10 mai 2009 15:56:09)

Thanks Yvan and Mark J. Reed
It works like a charm!