But there is a straightforward shell solution: simply write the list out to a file and then sort that:
set sortedList to paragraphs of (do shell script "sort -n -u " & quoted form of POSIX path of someFile)
(The annoying part of that solution, IMO, is the actual writing to a file, which is just far more work in AS than it seems like it should be. open for access, set eof, aliases vs files vs file specifications vs furls...)
I agree on both counts: for long lists writing data to a file is the only way to hand it over to the Unix system (or is there a direct way to put it into a Unix variable, like declaring an AppleScript variable visible to the Unix system?).
And writing files is extremely awkward in AppleScript. I tried the "write" command (ASLG p. 168), but failed: it seems that it can't write to a file before the file actually exits. That looks like a bug to me.
set theText to "Hello World"
set fileRef to ((path to temporary items) as text) & "tempFile.txt"
try
set fileHandle to open for access fileRef with write permission
set eof fileHandle to 0
write theText to fileHandle as «class utf8» starting at 0
close access fileHandle
on error err
display dialog "Problem: " & err
end try
If the file already exists and you want to use the same file over again, something like
set theText to "Hello World"
set fileRef to ((path to temporary items) as text) & "tempFile.txt"
try
set eof of file fileRef to 0
write theText to file fileRef as «class utf8» starting at 1
on error err
display dialog "Problem: " & err
end try
would work too, but you have to make sure that the file remains where it is, so the temp folder should be replaced by a place more stable.
Thomas