Re: are finder items items? what is a vector?
Re: are finder items items? what is a vector?
- Subject: Re: are finder items items? what is a vector?
- From: Deivy Petrescu <email@hidden>
- Date: Fri, 25 Dec 2009 14:26:08 -0500
On 25/12/2009, at 08:48 , Axel Luttgens wrote:
> Le 23 déc. 2009 à 22:44:23, Brennan a écrit :
>
>> [...]
>>
>> My script so far:
>>
>> tell application "Finder"
>>
>> set inverted to {}
>>
>> set fitems to items of window 1
>>
>> repeat with i in fitems
>>
>> if i is not in selection then
>> set end of inverted to i
>> end if
>>
>> end repeat
>>
>> set selection to {}
>> select inverted
>>
>> end tell
>>
>> I am getting stuck on the 'if' line - being told things like
>>
>> Can’t make «class cfol» "Address Book Plug-Ins" of «class cfol» "Library" of «class sdsk» of application "Finder" into type vector.
>>
>> [...]
>
> Hello,
>
> The "is in" operator is applied here to lists: a list contains another one if the latter is a sublist of the former.
> The operator thus expects two lists as operands.
>
> The error message tells that the "Finder item to list" coercion is an unknown operation.
>
> So, being explicit:
>
> if {i} is not in selection then
>
> allows to avoid that error message.
>
> But... above test appears to be always true.
> And indeed, one is now facing the fact that i, being the loop variable of a "repeat with variable in list" loop, is a reference of the form "item x of fitems", not the xth item of fitems itself. {i} is thus a list containing a reference, not a list containing a Finder item.
>
> As a result, one needs:
>
> if {contents of i} is not in selection then
>
> and the script now behaves as expected.
>
> HTH,
> Axel
First some comments on Axel's remark.
Axel is right, may be because the way it is written I always think of "is in" as "is x an element in a set y".
Actually "is in" really means is contained in. But it has some quirks...
Namely:
--------
set lista to {1, 2, 3}
if 1 is in lista then say "it is not supposed to be!"
delay 1
if {1} is in lista then say "now it got it right."
delay 1
set lista to {{1}, 2, 3}
if 1 is not in lista then say "this is what one should expect!"
delay 1
if {1} is in lista then
say "it is not supposed to be..."
else
say "ahhh, it got it right...{1} is not in lista!"
end if
delay 1
if {{1}} is in lista then say "{{1}} is in lista. This is the correct result!"
---------
Here is a script that does what you want.
It also allows you to select items in the desktop without having to open a window.
<script>
tell application "Finder"
set inverted to {}
set sel to selection as alias list
set cont to container of item 1 of (get selection) as alias
set fitems to every item of cont as alias list
repeat with i in fitems
set i to contents of i
if i is not in sel then set end of inverted to (i as alias)
end repeat
set selection to {}
select inverted
end tell
<script>
Deivy Petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden