Re: Why are these different?
Re: Why are these different?
- Subject: Re: Why are these different?
- From: Nigel Garvey <email@hidden>
- Date: Tue, 26 Feb 2002 18:45:53 +0000
Mr Tea wrote on Tue, 26 Feb 2002 10:20:48 +0000:
>
I recently tackled a question about a script that used the 'list folder'
>
command.
>
>
I wondered why the two lines below return different results:
>
>
'last item of (list folder myFolder)' returns the last item according to
>
alphabetical order
>
>
'last item of myFolder' returns the item that appears last when the contents
>
of myFolder are arranged by kind.
>
>
So, why the difference?
On my machines, 'last item of myFolder' also returns the last item by
alphabetical order.
*But* the Finder's "lists" of items are dynamic, not static. If you do
anything to an item in a folder - open it, close it, change its name,
etc. - or even just select it - then that item will become the 'last
item' in the folder. It seems to be the Finder's way of keeping track of
what's "on top".
Do something to another item and that will become the 'last item'. Close
the folder and run the test again, and the alphabetically last item will
be returned again.
This is a potential cause of problems when looping through Finder
references, as in:
repeat with thisItem in myFolder
... or:
repeat with thisItem in every item of myFolder
There's a real danger that doing something to an 'item' will change its
position in the Finder's "list" (or remove it entirely) on subsequent
iterations. It's usually safest to get a snapshot of the "list" as a
static AppleScript structure and to loop through that. Eg.:
repeat with thisItem in (get every item of myFolder)
NG
_______________________________________________
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.