• 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: Choose from List & Return Item Number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Choose from List & Return Item Number


  • Subject: Re: Choose from List & Return Item Number
  • From: "John C. Welch" <email@hidden>
  • Date: Mon, 21 Jan 2008 10:37:50 -0600
  • Thread-topic: Choose from List & Return Item Number

Title: Re: Choose from List & Return Item Number
On 01/21/2008 06:44 AM, "Rick Gordon" <email@hidden> wrote:

> Is there some variant on the Choose from List routine from Standard Additions
> that would allow the user to choose from a list and return the item number of
> the chosen entry, rather than the item as a string or integer?

Well, it’s not perhaps elegant as some other solutions, but why not just duplicate the list before the selection, then compare the choices to the copy, and add the index that way? It’s a bit brute force, but it works, although if you have really long lists, it would become somewhat inefficient. Then again, if you have really long lists, “choose from list” is somewhat inefficient too.

set
theList to {1, 2, 3, 4}
set
theIndexList to {}
set
theItems to choose from list theList with multiple selections allowed


repeat with x in theItems
   set theTest to contents of x
   set theIndex to 1
   repeat with y in theList
       if (contents of y) is equal to theTest then
           set the end of theIndexList to theIndex
       end if
       set theIndex to theIndex + 1   
    
end repeat
end
repeat

There’s probably better ways, but that one works, and is somewhat easy to read

--
"Any nation's attempt to dictate to other nations their form of government is indefensible."

Dwight D. Eisenhower, April 16, 1953
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Choose from List & Return Item Number (From: Rick Gordon <email@hidden>)

  • Prev by Date: Re: How to parse CSV
  • Next by Date: Re: Can't get finder selection
  • Previous by thread: Re: Choose from List & Return Item Number
  • Next by thread: Re: Choose from List & Return Item Number
  • Index(es):
    • Date
    • Thread