Re: Open Dialog Sort Order
Re: Open Dialog Sort Order
- Subject: Re: Open Dialog Sort Order
- From: Mr Tea <email@hidden>
- Date: Tue, 16 Dec 2003 01:59:47 +0000
This from Pat Stanford - dated 15/12/03 8.58 pm:
>
When I use a script to get a list of files in a folder it comes in in
>
normal expected ASCII order. When I look at the same folder in the open
>
file dialog, it is sorted differently. Why?
...and this from Mr Tea - dated 15/12/03 10.38 pm:
>
you'll need to repeat the Finder's trick by plucking
>
numbers from the beginning of file names
Ok, Pat. Maybe this will be of some use to you. It offers a way to turn your
first (script-generated) list into your second (Finder sort-order) list,
using a tweaked version of an ASCII sort routine that, if memory serves,
Nigel Garvey gave to the world.
--===========================================================
set startList to "150F77.dwg
150M75.dwg
200F45.DWG
200f45a.dwg
200F85.DWG
200M07.DWG
200M09.DWG
22C05.DWG
22C05NEW.DWG
22C05OLD.DWG
2B4P23.DWG
2B4P24.dwg
2BC01R.DWG"
set fileList to every paragraph of startList
set numFileList to {}
set ndx to ""
repeat with i from 1 to count of fileList
set f to item i of fileList
try
set ndx to text 1 thru 3 of f as integer
on error
try
set ndx to text 1 thru 2 of f as integer
on error
try
set ndx to text item 1 of f as integer
end try
end try
end try
if ndx is not "" then set end of numFileList to {ndx, f}
end repeat
set numFileList to ASCII_Sort(numFileList)
set sortedFileList to makeList(numFileList, fileList)
set textFileList to makeString(numFileList, fileList)
on ASCII_Sort(my_list)
set the index_list to {}
set the newList to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set currentItem to item i of my_list
set this_item to item 1 of currentItem
if the low_item is "" then
set the low_item to currentItem
set the low_item_index to i
else if this_item comes before item 1 of the low_item then
set the low_item to currentItem
set the low_item_index to i
end if
end if
end repeat
set the end of newList to the low_item
set the end of the index_list to the low_item_index
end repeat
return the newList
end ASCII_Sort
on makeList(numFileList, fileList)
set sortedFileList to {}
repeat with itm in numFileList
set end of sortedFileList to item 2 of itm
end repeat
repeat with itm in fileList
try
text item 1 of itm as integer
on error
set end of sortedFileList to itm
end try
end repeat
return the sortedFileList
end makeList
on makeString(numFileList, fileList)
set textFileList to ""
repeat with itm in numFileList
set textFileList to textFileList & item 2 of itm & return
end repeat
repeat with itm in fileList
try
text item 1 of itm as integer
on error
set textFileList to textFileList & itm & return
end try
end repeat
return the textFileList
end makeString
--===========================================================
The makeString routine returns a return delimited text list like the one
printed in your original post, the makeList routine returns a list of
strings (or whatever, depending on how you adapt the script, if you use it)
which might be a better option for the purposes of any further processing
that you want to do.
HTH.
Nick
pp Mr Tea
_______________________________________________
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.