Re: How to get the index of an item in a list
Re: How to get the index of an item in a list
- Subject: Re: How to get the index of an item in a list
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 25 Jun 2001 02:38:14 -0700
On 6/25/01 12:45 AM, "Greg Strange" <email@hidden> wrote:
>
I have tried this (I'm heavily paraphrasing):
>
>
display dialog "Which one?" default answer "" buttons {"Get Description",
>
"Cancel"}
>
set yourDesc to the text returned of the result
>
if yourDesc is "Get Description" then
>
set theIndex to the index of yourDesc in theFirstList
>
set theAnswer to item theIndex of theSecondList
>
>
This does not get me what I want. It says that it "can't get yourDesc of
>
{"firstItem", "secondItem", "thirdItem"}"
>
>
I can see where I could loop through with a counter and get it but isn't
>
there a better way?
Not in pure AppleScript there isn't. You can use Akua Sweets;
set theIndex to item 1 of (collect items of theFirstList that match
yourDesc)
which is a lot easier to script, but the repeat loop in pure AppleScript is
actually faster OMM any time I've tested since about OS 8.6 or 9.0.
--
Paul Berkowitz