Re: Number Of Chosen Item
Re: Number Of Chosen Item
- Subject: Re: Number Of Chosen Item
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 21 Jan 2004 01:31:02 -0800
On 1/21/04 12:56 AM, "Ben Gummer" <email@hidden> wrote:
>
I am trying to make a script that lets the user choose from a list of
>
values. Once they have selected, it returns the item number that they
>
chose. For example, if they picked "Text3", it would return "3". I have
>
tried doing this with the following script, but its not working....
>
>
set FeedTitles to {"Text1", "Text2", "Text3"}
>
set ChosenItem to choose from list FeedTitles
>
set ItemNumber to item number of ChosenItem in FeedTitles
Unfortunately AppleScript has no native 'index' property of list items. You
have to do it by a handler (also note that 'choose from list' returns a
sublist, so you have to get 'item 1' or else coerce the list to string):
set FeedTitles to {"Text1", "Text2", "Text3"}
set ChosenItem to item 1 of (choose from list FeedTitles)
set ItemNumber to CollectUniqueItemIndex(FeedTitles, ChosenItem)
to CollectUniqueItemIndex(theList, theItem) -- the Item can be string,
number, constant, app object or list
local aListMember
set theIndex to 0
repeat with i from 1 to (count theList)
set aListMember to item i of theList
if aListMember = theItem then
set theIndex to i
exit repeat
end if
end repeat
return theIndex
end CollectUniqueItemIndex
If you have very long lists (more than 100 items, say) you can incorporate a
script object to speed it up greatly. Ask.)
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.