Re: Choose from List & Return Item Number
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