Selected Finder items returned by index?
Selected Finder items returned by index?
- Subject: Selected Finder items returned by index?
- From: "Bob.Kalbaugh" <email@hidden>
- Date: Sun, 14 Oct 2001 22:05:20 -0500
Can someone confirm this?
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? BTW, for anybody listening - selecting edit-copy
from the Finder menu, yields the same results (clipboard).
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?
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.
Thanks a bunch in advance.
_bob.kalbaugh
With some items selected...
-- kludge 1 (slow) --
tell application "Finder"
activate
set itemList to {}
set itemSelection to (sort the selection by name)
repeat with i in itemSelection
copy (name of i) to end of itemList
end repeat
end tell
itemList
-- end --
--- kludge 2 (somewhat faster) ---
tell application "Finder"
activate
copy -- why this works alphab'y here, and not manually - ???
set itemList to (the clipboard as string) -- thanks N.G.!
end tell
set newList to (every paragraph of itemList) as list
--- end ---