Re: Finder selection
Re: Finder selection
- Subject: Re: Finder selection
- From: John Stewart <email@hidden>
- Date: Mon, 14 Mar 2005 07:48:38 -0500
On 03/14/05 at +0100 Brennan said this
> The Finder selection is a strange beast. I wish to use it often, and
> then
> am confounded by the inscrutable results.
This type of thing isn't confined to the Finder.
> It appears to be a list, but isn't. I've learned that, regardless of how
> many items are selected:
Isn't a list, is a property containing a reference and that's the key to using it.
> (count selection) -- always returns 0
> (files of selection) -- always returns {}
> (items of selection) -- always returns {}
As stated above, "selection" contains a reference to what's currently selected in the Finder. You need to resolve that reference before you can do anything useful with it.
> Presumably this is because 'selection' does not have a class defined. Is
> this just something which has not been filled in yet. It certainly seems
> like a shortcoming.
Actually it does have a class -
tell application "Finder" to class of selection
--> property
> 'selection' can be coerced to list, but one irritating consequence of this
> is that we can't then use the filter reference form to extract things from
> it, e.g. there is no way to do something like this:
>
> (items of selection whose name contains "x")
It's unfortunate that whose clauses don't apply to lists. It would be so helpful in so many cases. Fortunately when working with the Finder there are ways to aviod this, not using a selection is one way.
> Finder items do not have a 'selected' property either, which might have
> been a viable workaround:
>
>Do other people use the Finder selection? Have you learned anything
>useful?
This is one of those times where you need to either use an explicit get or to work within a variable because you need to resolve a reference.
With 3 items selected in the finder all of the following will resolve to a list of references. -
tell application "Finder" to count of (get selection)
--> 3
tell application "Finder" to class of (get selection)
--> list
Or use something like this if you need to make more than one use of it.
tell application "Finder" to set s to selection
count of s
--> 3
class of s
--> list
JBS
--
When you are dissatisfied and would like to go back to youth, think of Algebra. — Will Rogers
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden