• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Number Of Chosen Item
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Number Of Chosen Item (From: Ben Gummer <email@hidden>)

  • Prev by Date: Re: ASCII vs. MacRoman
  • Next by Date: Re: UI Scripting and sub-sub-menus in Photoshop
  • Previous by thread: Number Of Chosen Item
  • Next by thread: Still more strange things …
  • Index(es):
    • Date
    • Thread