Re: last does not work with filter expression?
Re: last does not work with filter expression?
- Subject: Re: last does not work with filter expression?
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 04 Feb 2005 17:11:44 -0800
On 2/4/05 4:40 PM, "Michael Johnston" <email@hidden> wrote:
> I found the following oddity. I'm not sure whether it belongs to
> OmniOutliner, Applescript, or my own faulty understanding of
> Applescript*.
>
> say I have a row with two children, row1 & row2, both with style "bob"
> then I get the following results
>
> last row of theRow
> -- row2
>
> set theList to every row of theRow where name of named style 1 of style
> of it = "bob"
> last item of theList
> -- row2
>
> last row of theRow where name of named style 1 of style of it = "bob"
> -- row1 //WHY?
>
Once you've created an AppleScript list you cannot apply 'whose' filters to
it since AppleScript lists and records do not support 'whose' filters. Chris
Nebel confirmed this yet again just a day or two ago, and confirmed that it
is a long-standing request.
You can only apply 'whose' filters directly to plural application objects in
applications which implement them - which should be clear if the objects
are listed as elements - of the application or of some container object -
'satisfying a test' in the app's dictionary.
I see from OmniOutlinerPro's dictionary that both 'row' and 'child' are
indeed elements that can be specified 'satisfying a test'. There you ought
to be able to get
last row of theRow where name of named style 1 of style of it = "bob"
as you say.
What you're dealing with here is two different "interpretations" of 'last'.
In the line above, 'last' _probably_ means "last to be created", but we
don't know for sure: you'll have to ask the developers how rows are ordered
from first to last for AppleScript.
In your counter-example:
set theList to every row of theRow where name of named style 1 of style
of it = "bob"
last item of theList
the order of 'every row' is not guaranteed to be in creation order, or in
any other order. Again you'll need to ask the developers if there is a
stipulated or expected order. Having got the list, 'last item' is an
AppleScript definition , fetching the final item, of the ordered list. It
appears that 'every row...' formed the list as {row2, row1}. You'll need to
ask the developers why - it might be a bug, or it might just not be
specified.
I notice that 'row' has an 'index' property:
index - integer -- The index of the row among its siblings
and 'siblings' mist be determined by the 'level' property:
level - integer [r/o] -- How 'deep' this item is. Top-level rows are
level 1, subtopics of those rows are level 2, and so on.
So it looks as if the developers do intend to create a clear order. In that
case they may consider this a bug that they will fix. In the meantime, maybe
this will work?
set theList to every row of theRow where name of named style 1 of style
of it = "bob"
set x to 0
repeat with i from 1 to count theList
set theItem to item i of theList
set theIndex to index of theItem
if theIndex > x then set x to theIndex
end repeat
row x of theRow
Slower, but as I said, you can't apply 'whose' filters to lists. If the
result confirms your first version so you can trust _its_ definition of
'last', always, then go with
last row of theRow where name of named style 1 of style of it =
"bob"
That will always be easier and faster, if it's accurate.
--
Paul Berkowitz
_______________________________________________
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