Re: Choose from List & Return Item Number
Re: Choose from List & Return Item Number
- Subject: Re: Choose from List & Return Item Number
- From: Skeeve <email@hidden>
- Date: Mon, 21 Jan 2008 13:59:17 +0100
Rick Gordon 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?
No I said before.
But here is a handler with 2 examples doing (maybe) what you need:
choose_index from {"two", "Two", "TWO"} without title, default,
ok_button_name, cancel_button_name, multiple_selections and
empty_allowed given start_numbering_at:1, prompt:"Which 2?"
choose_index from {"MCMXCIIX", "MCMXCIX", "MM", "MMI"} without
multiple_selections and empty_allowed given start_numbering_at:1998,
prompt:"Which year??", default:"MM", title:"Roman Years",
ok_button_name:"This one", cancel_button_name:"None"
to choose_index from a_list given start_numbering_at:frst,
title:headline, prompt:question, default:selected,
ok_button_name:ok_btn, cancel_button_name:cancel_btn,
multiple_selections:multi, empty_allowed:mt
if class of frst is not integer then set frst to 1
if class of headline is boolean then set headline to ""
if class of ok_btn is boolean then set ok_btn to "OK"
if class of cancel_btn is boolean then set cancel_btn to "Cancel"
set display_list to {}
set selected_list to {}
set idx to frst
repeat with element in a_list
set displayable to (idx as string) & ")" & tab & element
if selected contains element then copy displayable to the end of
selected_list
copy displayable to the end of display_list
set idx to idx + 1
end repeat
if question is false then
set auswahl to choose from list display_list with title headline
default items selected_list OK button name ok_btn cancel button name
cancel_btn multiple selections allowed multi empty selection allowed mt
else
set auswahl to choose from list display_list with title headline
with prompt question default items selected_list OK button name ok_btn
cancel button name cancel_btn multiple selections allowed multi empty
selection allowed mt
end if
if auswahl is not false then
repeat with i from 1 to count of auswahl
set the_text to item i of auswahl
set item i of auswahl to (text 1 thru (-1 + (offset of ")"
in the_text)) of the_text) as integer
end repeat
end if
return auswahl
end choose_index
_______________________________________________
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