: first off i wanted to thank everyone for their responses to my other newbie
: questions.
: this hasn’t presented a problem yet, but i’m curious why applescript is
: behaving this way: Say i have a folder called “My Folder” which
: contains the following five files: image1.jpg image2.jpg image3.jpg
: image4.jpg image5.jpg
: now what tends to happen every other day it seems is that getting the first
: item of the folder which actually get the second item in the folder,
: i.e. the following code: – begin code
: tell application “Finder” to get item 1 of folder “My
: Folder”
: – end code
: returns image2.jpg! Along the same lines, the following code: – begin code
: tell application “Finder” to set fileList to name of every file in
: folder “My Folder”
: – end code
: returns the list
: {“image2.jpg”,“image3.jpg”,“image4.jpg”,“image5.jpg”,“image1.jpg”}
: this hasn’t posed a problem yet because I happen to be processing every file
: in the folder, so the order doesn’t really matter. But i’m curious to know
: what’s going on here- especially because sometimes the problem seems to go
: away for no discernible reason, and i could see it being a possible
: problem in the future…
I’m not sure of the answer but obviously the index order is not the same as the alphabetical order. Did you, by any chance, create or modify image1.jpg after the rest of them?
You can use the Finder’s “sort” command to return a list of the contents of a container by name and then extract the names in order to another list:tellapplication “Finder” setxto (sortitemsof (choose folder) byname) setnameListto {} repeatwithanIteminx setendofnameListtonameofanItem endrepeat endtell nameList Marc K. Myers Marc@AppleScriptsToGo.com AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
: first off i wanted to thank everyone for their responses to my other newbie
: questions.
: this hasn’t presented a problem yet, but i’m curious why applescript is
: behaving this way: Say i have a folder called “My Folder” which
: contains the following five files: image1.jpg image2.jpg image3.jpg
: image4.jpg image5.jpg
: now what tends to happen every other day it seems is that getting the first
: item of the folder which actually get the second item in the folder,
: i.e. the following code: – begin code
: tell application “Finder” to get item 1 of folder “My
: Folder”
: – end code
: returns image2.jpg! Along the same lines, the following code: – begin code
: tell application “Finder” to set fileList to name of every file in
: folder “My Folder”
: – end code
: returns the list
: {“image2.jpg”,“image3.jpg”,“image4.jpg”,“image5.jpg”,“image1.jpg”}
: this hasn’t posed a problem yet because I happen to be processing every file
: in the folder, so the order doesn’t really matter. But i’m curious to know
: what’s going on here- especially because sometimes the problem seems to go
: away for no discernible reason, and i could see it being a possible
: problem in the future…
I just did some quick testing with this and it appears that the modification
date might alter the order in the list. The test involved 5 newly created files
with the same names used in the example above. On the first run, the
result was a list of files in numerical order (1, 2, 3, 4, 5), as you desire.
I then switched the names of 2 of the files, and the order of the resulting
list was changed.
Assuming that at least some of your files are being modified somewhere
along the way, and you are seeing this randomly, this might be a
reasonable explanation (although maybe not a reasonable way to
handle it on AppleScript’s part).
FYI, testing was done using OS 9.1 and AppleScript 1.6.
– Rob