Re: Selected Finder items returned by index?
Re: Selected Finder items returned by index?
- Subject: Re: Selected Finder items returned by index?
- From: Charles Arthur <email@hidden>
- Date: Mon, 15 Oct 2001 14:38:05 +0100
On Sun, 14 Oct 2001 22:05:20 -0500, "Bob.Kalbaugh"
<email@hidden> wrote:
>
I've noticed that the Finder appears to return selected items by index. I'm
>
on OS 8.5.1, AS 1.3.4 With the root folder open and all items selected I
>
run...
>
>
tell application "Finder"
>
activate
>
set items_selected to (name of selection)
>
end tell
>
-->{"System Folder", "Utilities", "Font Library", "Etc..."}
>
>
If I randomly open some of the folders, close them, select all, and run the
>
script again I get different results. So it appears that the items are
>
returned by index, yes?
Well, you're selecting things and it's reading their name. Yes, probably
the order they're returned in is to do with the unique index that MacOS
gives files.
>
BTW, for anybody listening - selecting edit-copy
>
from the Finder menu, yields the same results (clipboard).
That's because you've copied the name of the selection to the clipboard.
You can do it with the contents of a folder too - try opening a folder with
lots of files, Apple-A, Apple-C, then open a text/WP window and Apple-V.
Voila, list of files and folders in the folder.
>
I'd like to have them returned alphabetically. The Finder's sort reference
>
by property command sorts correctly, but I can't seem to glean the name from
>
the result without adding a repeat loop. I've tried too many iterations to
>
list but one example along the lines of what I'm trying is:
>
>
set items_selected to (name of (sort selection by name))
>
>
most result in:
>
--> Can't get name of {folder "Applications" of startup disk of application
>
"Finder" ...} - is this not a reference?
No. As the curly brackets imply, it's a list. "Name of" only works on one
Finder item at a time.
For example, if you highlight one item (say, a disk) and try
tell application "Finder"
set items_selected to (name of (sort selection by name))
end tell
--> fails.
But
tell application "Finder"
set items_selected to ((name of (sort selection by name)) as string)
end tell
--> works, for a SINGLE selected item. However if you Apple-A an opened
folder to highlight many files, it fails. You can't get the name of a
multi-item list. It doesn't really make sense, after all.
>
Can someone tell me how to properly use the sort by command? After a lot of
>
playing, the following 2 snippets return what I want, but are kludgey at
>
best. I'll probably stick with the second one unless someone can offer
>
better, or advise that it's not a good idea.
You'd have to use a repeat loop. Or your Kludge 2. The latter looks more
elegant. You are constrained here by the fact that you're trying to grab a
property of multiple items out of a list.
Charles
----------------------------
http://www.ukclimbing.com : 1000+ British crags, 350+ British climbing
walls - searchable by distance and anything else you care to think of -
with weather forecasts for every one, plus maps, articles, news and
features. Plus Britain's busiest climbing discussion boards. And there's
even a cool shop attached.
_____________________________________________________________________
This message has been checked for all known viruses by the
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp