Re: Sorting A List - Need Help
Re: Sorting A List - Need Help
- Subject: Re: Sorting A List - Need Help
- From: "Steven D. Majewski" <email@hidden>
- Date: Sat, 26 Jul 2003 19:00:06 -0400
Quick hack to make my previously posted sort routine work with
filenames with embedded spaces:
( however, it works only with embedded space and no longer uses "_"
as sort field delimiter. )
property d : (ASCII character 34) & space & (ASCII character 34)
property quot : (ASCII character 34)
-- change delimiter to joinby to quot & space & quot
-- and append another pair of quotes to beg. and end of string
-- so all args are quoted.
-- us "quoted form of" on arglist so the quotes are not lost.
-- change sort delim to space.
on nat_order(unorder)
set order to quot & joinby(unorder, d) & quot
do shell script "echo " & quoted form of order & " | xargs -n 1 echo |
sort -n -t ' ' +0 +1"
return every paragraph of result
end nat_order
on joinby(somestrings, delim)
-- join list of strings by delim char
try
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set retval to somestrings as string
set AppleScript's text item delimiters to oldDelim
on error
set AppleScript's text item delimiters to oldDelim
end try
return retval
end joinby
set test to {"untitled 1", "untitled 2", "untitled 12", "untitled 20",
"untitled 3"}
nat_order(test)
--> {"untitled 1", "untitled 2", "untitled 3", "untitled 12", "untitled
20"}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.