Hi… I found this while doing a search on this board-- and I needed a way to take a large list and alphabetize it but add carriage returns after each line-- so I added the \n to it…
on sort_list(the_list)
set nl to (ASCII character 10)
tell (a reference to my text item delimiters)
set {old_delim, contents} to {"\n", contents, nl}
set {the_list, contents} to {"" & the_list, old_delim}
end tell
return paragraphs of (do shell script "echo " & (quoted form of the_list) & " | sort")
end sort_list
Everything seemed great, except I started experiencing STRANGE behavior…
My assumption was that with this code, I could just say:
my sort_list(list1)
set list1 to the result
my sort_list(list2)
set list2 to the result
— what I found was that, all lists from then on were automatically being affected by sort_list…
I could just say:
my sort_list(list1)
and list2 would automatically be affected, and I was experiencing carriage returns in places where I didn’t even want them!!!
example, I then had:
set bla to count & " hello there, here is a list: " & list2 as string
– and I would get
72
hello there, here is a list:
apple
dog
grape
igloo
…
So, can someone please break this down for me-- tell me what is going on, and how can I avoid this?
and also-- is there a way to include case insensitivity to this sorting so that I can have
jason
Jerry Seinfeld
jimmy johnson
lucky
Man in the moon
etc…etc.etc
thank you!