How to get the index of an item in a list
How to get the index of an item in a list
- Subject: How to get the index of an item in a list
- From: Greg Strange <email@hidden>
- Date: Mon, 25 Jun 2001 02:45:49 -0500
I'm sitting here. At 2:37 in the morning. Wanting to get the index of an
item in a list. You are there. Sleeping. Not wanting the index of an item
in a list. When you wake up, will you consider my plight?
I have two lists. One list is like this:
set theFirstList to {"firstItem", "secondItem", "thirdItem"}
set theSecondList to {"The first name is great","The second item is
unoriginal", "This is silly."}
I want to allow the user to pick the name of the item in the first list and
get the correct item from the second list.
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?
Thanks for your waking help,
Greg Strange
__________________________________________________________________
Writing AppleScripts? Got a bunch of code snippets laying around?
Want to add them to a list of modules that every scripter could use?
Go to
http://applemods.citizenstrange.com