• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting A List - Need Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting A List - Need Help


  • Subject: Re: Sorting A List - Need Help
  • From: "Steven D. Majewski" <email@hidden>
  • Date: Sat, 26 Jul 2003 18:07:27 -0400

I had a similar but less general problem.
A scanner produces a folder of files with names like:
1_1
1_2
...
1_10
1_11
..
2_1
2_2 ...

which the finder seems to sort as above, but when we load them into
another program, the don't get loaded in finder order. I was also
disappointed to find that 'list folder' doesn't deliver the files in "finder
order" .

I used the following applescript procedure to send the files out to unix
sort, and to sort numerically by the two "_" separated fields:


on nat_order(unorder)
set order to joinby(unorder, space)
do shell script "echo " & 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

nat_order({"untitled_1", "untitled_2", "untitled_12", "untitled_20", "untitled_3"})


--> {"untitled_1", "untitled_2", "untitled_3", "untitled_12", "untitled_20"}


However, if you change the " -t '_' " to " -t ' ' " , the files will get split on the spaces
before they go to sort. The xargs was just to avoid having to use a temporary file
though, so if you put them in a tempfile and sort them, it can manage the spaces.

The other thing is that, since the finder does order the underscore files as well as
ones with embedded spaces, it would seem that the finder handles multiple
delimiters between numeric fields. ( It would be nice to know what the actual
algorithm for "Finder order" is -- there are places where it would be "least surprising"
to be able to present files in the same order that the Finder does. )

I can think of other ways to coerce unix sort to do the job here, but if you require
the same behaviour, at that point, I'ld probably just write a sort in AppleScript that
does what I want.

-- Steve Majewski
_______________________________________________
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.

  • Follow-Ups:
    • Re: Sorting A List - Need Help
      • From: "Steven D. Majewski" <email@hidden>
References: 
 >Sorting A List - Need Help (From: Rick Bargerhuff alias cougar <email@hidden>)

  • Prev by Date: (no subject)
  • Next by Date: Re: Sorting A List - Need Help
  • Previous by thread: Re: Sorting A List - Need Help
  • Next by thread: Re: Sorting A List - Need Help
  • Index(es):
    • Date
    • Thread