I assembled some batch file renaming tools for OS 9 that would sort a list of selected files from oldest to newest, ask for a name, number to begin, and a file extension. They work in OS X if I remove the ‘sort’ portion of the script, as ‘X’ has no sort command (right?). I’ve been messing with the ‘arrange’ command in ‘X’ for a similar result with no luck.
***** Anyone (Nigel?) have a routine to add to my OS X script that will:
Sort a selected list by modification date?**********
The scripts are in code builders and are named “File Naming Tools”. Sorting by creation date is needed because if I have files created in this order,
bTV movie 1.mpg
bTV movie 2.mpg
bTV movie 3.mpg
bTV movie 1.mpg.1
bTV movie 2.mpg.1
bTV movie 3.mpg.1
bTV movie 1.mpg.2
bTV movie 2.mpg.2
bTV movie 3.mpg.2
they get processed by name instead of creation date:
bTV movie 1.mpg
bTV movie 1.mpg.1
bTV movie 1.mpg.2
bTV movie 2.mpg
bTV movie 2.mpg.1
bTV movie 2.mpg.2
bTV movie 3.mpg.
bTV movie 3.mpg.1
bTV movie 3.mpg.2
and then renamed, which totally screws the order up by which they were made.
But I don’t know if it works with OS 10.1. (Not tested there.) It certainly does with 10.2 and I’ve had no negative feedback about 10.3. You could give it a try. You can either copy/paste it into your script or, since it’s two very large handlers, load it separately as a library.
Like the old Finder ‘sort’ command, it needs a Finder reference to work on. If you’re going to be using it to sort items dragged onto a droplet, the trick with the selection won’t work in X. However, the following’s quite quick-acting and works provided that all the dragged items are in the same folder:
on open droppedItems
tell application "Finder"
set theContainer to container of (item 1 of droppedItems)
repeat with thisItem in droppedItems
set contents of thisItem to name of thisItem
end repeat
set fRef to a reference to (items of theContainer whose name is in droppedItems) -- NB. 'a reference to'
set sortedItems to my FinderSort(fRef, "modification date")
--> A list of Finder references, sorted by modification date
--etc.
end tell
end open
The above assumes that the FinderSort() code has been pasted into the same script as the open handler. Let me know if it works for you…
Hi, Todd. It would help to know what command(s) 10.1 doesn’t understand before fishing around for other solutions that may be subject to the same problem(s). Could you please paste the FinderSort() and CustomQsort() handlers from the downloaded script into the following code, run it in Script Editor, and tell me what happens? (ie. Do you get a properly date-sorted result in SE’s Result window? Are any errors thrown? If so, what’s reported and what’s highlighted in the script?)
set testFolder to (choose folder) -- something with not too many items for this test
tell application "Finder"
try
set droppedItems to (items of testFolder) as alias list
on error
set droppedItems to (item 1 of testFolder) as alias as list
end try
set theContainer to container of (item 1 of droppedItems)
repeat with thisItem in droppedItems
set contents of thisItem to name of thisItem
end repeat
set fRef to a reference to (items of theContainer whose name is in droppedItems)
set sortedItems to reverse of (my FinderSort(fRef, "modification date"))
end tell
-- Paste FinderSort() and CustomQsort() handlers here
If you’re not interested in having FinderSort() as a (hopefully temporary) general replacement for the Finder’s ‘sort’ command, it’s possible to use just the CustomSort() handler for your purposes. But it would still be helpful to know how the above code fares first.