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: Tue, 16 Oct 2001 11:25:12 +0100
At 4:42 pm -0500 on 15/10/2001, Bob wrote:
>
> 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.
>
>
You're right. It doesn't make one bit of sense. If you can loop through it
>
then I would think you should be able to get the names with a statement
>
like: name of every item in item_selection
You can loop through it but that then makes "every item" redundant.
eg, having got items_selected as your list of Finder items
repeat with theloopitem in items_selected
display dialog name of theloopitem
end repeat
What I found difficult when beginning AScript was understanding quite what
sort of item "theloopitem" would be in a repeat loop like this. It's not
like "repeat with j from 1 to 10" where j is a loop counter, and a simple
integer. Instead, here, "theloopitem" is the list item itself (or a
reference, which makes no difference in this context).
Sometimes this sort of thing can catch you out nastily, and cause really
weird errors that you can't wrap your head around until you examine your
assumptions about what identity you think the loop item has, and comparing
it to what is actually happening there.
A big diversion to explain, anyway, why
repeat with theloopitem in items_selected
display dialog name of every item in theloopitem
end repeat
is overkill. "Every item" of one item is the same as the item.
>
I can state: name of item 3 in item_selection and as long as there *is* a
>
3rd item it returns. Once again I'm left scratching my head.
Is it surprising now? You're given a shopping list and told to name the
third item. It reads: "Bread sugar flour". You say "flour". Another
shopping list, same instruction: "Bread sugar". You say: "huh?"
>
Thank you Charles. I was leaning towards kludge 2, but since Nigel Garvey
>
noted some problems with it I'm not sure. I can't seem to reproduce the same
>
problems he was having. I'm not sure, exactly, what he found.
The problem with the repeat loop is that if you're looking for maximum
speed (as true Jedi Knights - now an Official Religion in the UK! according
to latest census - always are, often at the cost of hours and hours staring
at code) then you'll want to do the repeat loop outside a Finder tell loop.
However this causes problems when the thing you want to find out - such as
name - needs the Finder to answer it. There's no good answer.
>
There has got to be a way to get those names... I'll keep playing, I've got
>
some time to kill.
You'll need it, but the investment may be worthwhile.
best
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