Alphabetizing

Does anyone know of a quick way to alphabetize a list of words. I have a list that I want to display in alphabetic order.

Thanks,
jON bEEBE

Hi Jon,

See this thread http://bbs.applescript.net/viewtopic.php?id=5193 for a fast list sorting handler.

Best wishes

John M

There are lots of ways to sort lists. For things like this, I like using the sort command line tool:

set the_list to {"words", "of", "a", "list"}
set ascii_10 to ASCII character 10
tell (a reference to my text item delimiters)
	set {old_atid, contents} to {contents, ascii_10}
	set {the_list, contents} to {the_list as Unicode text, old_atid}
end tell
set the_list to (do shell script "echo " & quoted form of the_list & " | sort")'s paragraphs

Any other Jo(h)ns want to join this thread?

Jon

With apologies for being named Adam instead of Jo(h)n, isn’t there a limit on how large a list passed to a shell script can be? What it it? Is there any warning that the limit has been exceeded?

In a thread sometime ago, jj proposed that it was significantly faster when dealing with large lists (for reasons having to do with how they are stored) to go this route:

script TL
property the_list : {}
end script
--
set TL's the_list to Original_List
set ascii_10 to ASCII character 10
tell (a reference to my text item delimiters)
	set {old_atid, contents} to {contents, ascii_10}
	set {the_list, contents} to {the_list as Unicode text, old_atid}
end tell
set TL's the_list to (do shell script "echo " & quoted form of (TL's the_list) & " | sort")'s paragraphs

Is that valid when passing the list to a shell script?

I would like to thank everyone for there replies…they solved my problem very wel!. Just a note: The link suggested here http://bbs.applescript.net/viewtopic.php?id=5193 worked much slower than the shell script (on a list of 373 words). The AppleScript routine will sort numbers first, then both Capitalized words and lowercase words together, which is what I needed. The shell script method put all numbers first, then Capitalized words, then lowercase words. I changed it to the following:

set the_list to (do shell script "echo " & quoted form of the_list & " | sort -f")'s paragraphs

The “-f” flag at the end sorted Upper and lower case words together.

Thanks again!
jON bEEBE