Re: Selected Finder items returned by index?
Re: Selected Finder items returned by index?
- Subject: Re: Selected Finder items returned by index?
- From: Nigel Garvey <email@hidden>
- Date: Tue, 16 Oct 2001 03:28:48 +0100
"Bob.Kalbaugh" wrote on Mon, 15 Oct 2001 12:36:41 -0500:
>
>
>
> 'Sort' is a command - which produces its own result - so the reference
>
> chain is broken at that point.
>
>
You had mentioned before that "It's always safer to resolve an application
>
list reference..." Is that what the sort command returns? It's not an object
>
reference then? Maybe an application list of object references? I don't
>
understand how I can loop through it and get the names, but not in one
>
she-bang like:
>
>
set items selected to (sort selection by name)
>
name of every item in items_selected
Well that's two she-bangen. There are three ideas to grasp here:
references (in particular application references, in particular Finder
references), commands, and results.
A Finder reference is a description that the Finder understands of
something internal to the Finder - eg. 'selection', 'every item of the
desktop', 'front window', 'every folder of startup disk whose name
contains "aardvark"', and so on. If you resolve a reference by using it
in a 'get' or 'set' command, the Finder will supply your script with a
result. This result is your script's version of whatever's meant by the
reference. The Finder itself may or may not be able to understand it,
depending on what it is and how it's used.
Other commands may also return results and the 'sort' command is one of
these. 'Sort selection by name' is a command to the Finder to ... uh ...
sort the selection - though it doesn't actually sort the selection
itself. It returns a sorted result to the script. If only one item is
selected, the result is a reference to that item; otherwise the result is
a list, which contains Finder references but isn't one itself.
The expression 'name of selection' is another Finder reference, which can
probably be regarded as an extended one. Its slightly unusual because the
'selection' includes every item of the selection, so the implication is
'name of every item of selection'. When it's all together on one line,
it's one reference and the Finder understands it. If it's split over two
lines:
set fred to selection
name of fred
... the Finder's being asked to get the name of the previous result, not
the selection itself. If the previous result was a list, then the
instruction's nonsense and an error is generated. Similarly with 'sort'.
This is a command ("do this"), not a reference ("this object
description"), and it returns a result which is either a single reference
or a list of them. Placing 'name of' in front of it makes the Finder
attempt to get the name of this result.
I hope this is coherent. It's about three twenty in the morning here.
>
>> --- 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
>
>
>
> I was quite excited by this at first; but as I began to fool around with
>
> the selected items, I found the clipboard order began to change. It's not
>
> a safe method.
>
>
>
> NG
>
>
YES!, as was I when I stumbled upon it. Your finding has caused me great
>
dismay, as I wanted to share this script. Darn it! Can you please give me an
>
example? I'm not sure how you fooled with the selected items and I've tried
>
to reproduce your result, but I consistently get an alphabetical list. I'm
>
wondering if it's system or AS related. Again I'm on 8.5.1 with AS v1.3.4
>
Finder v 8.5
I was experimenting with the items that happen to be on the desktop on my
8.6 machine. Selecting some or all of the items and running the script
produces an alphabetical list until I open any of the items by
double-clicking it. The next time I run the script, the name of the
opened item has moved to the end of the list. It stays there until it
becomes penultimate to whatever's opened next. I've just tried it again
with the items in an ordinary folder with the same results. However, if I
close the folder and then reopen it, the alphabetical clipboarding of its
contents is restored. Maybe that would help.
>
Nigel, Thanks again for your insight. So helpful, often clever and much
>
appreciated!
Don't make me cry. It's been a difficult weekend! ;-)
NG