list folder, sorting by name

Hi, I’m re-posting this in the appropriate forum. Sorry if you’ve seen this is the AppleScript OSX forum, I meant to put it here.

I’ve created an AppleScript Studio application that helps rename photo files for a project I’m working on. When the program is launched, it gets a list of all the files in a specific folder, then shows the first one on screen. After I enter a new name, it renames the file, moves it to a new folder and shows the next one, and so on.

It works, but there is an oddity that I can’t quite figure out. When the program launches, this is the code it uses to get a list of the files I’ll be renaming:

set fileNames to (list folder "Drive1:unnamed:" without invisibles )

Then I show the first image and proceed from there.

The oddity is that when I move images into the folder containing images to rename (manually in the Finder), it copies them in a somewhat random order. This isn’t a problem in the Finder, but once the image naming application cycles through images, it displays them in the exact same order they were copied.

I don’t know why it does this, but I manually tried copying images in different orders, and no matter what the filename is, it displays them in whatever order they were copied in.

I’m very new to AppleScript, so is there an easy way to sort the fileNames list?

Thanks,
Dave Heinzel

From your opening comment it doesn’t appear you’re looking for an OS X solution, but just in case I offer this approach. (I don’t mean this as a complete flawless solution (maybe quotes or embedded spaces could cause problems)).

set {saveDelims, text item delimiters} to {text item delimiters, ASCII character (13)}
set lst to list folder "Drive1:unnamed:" without invisibles
set x to do shell script "echo "" & lst & ""|sort"
set sortedList to text items of x
set text item delimiters to saveDelims

This works for me, anyhow…For OS9 I or others can provide a sorting algorithm if you wish…

  • Dan

Thanks dant!

I am working in OSX, but I meant to post in the AppleScript STUDIO forum and not just an AppleScript forum.

Your code worked flawlessly with a few modifications for my own purposes. Thank you very much!

-Dave

Glad it worked-you’re very welcome!