Choose from list
Choose from list
- Subject: Choose from list
- From: Stephen Swift <email@hidden>
- Date: Sun, 05 May 2002 19:21:09 -0400
I love choose from list because it offers more options instead of the 3
button alternative. However, my problem arises when the script has to
determine what option the user selected and what course of action to take
from there. (*Speed Freak Alert*) Sure, there is the classic if then
statement but is it the most efficient, the fastest? Could I instead use
some sort of repeat loop or something?
My script example:
set thelist to {"Dialog Box 1", "Dialog Box 2", "Dialog Box 3", "Dialog Box
4"}
--watch for line break
set theDialog to choose from list thelist
if item 1 of theDialog is item 1 of thelist then
display dialog "Good Morning"
else if item 1 of theDialog is item 2 of thelist then
display dialog "Good Afternoon"
else if item 1 of theDialog is item 3 of thelist then
display dialog "Good Evening"
else if item 1 of theDialog is item 4 of thelist then
display dialog "Good Night"
end if
Ideally I would like something like this:
set option1 to display dialog "Good Morning"
set option2 to display dialog "Good Afternoon"
set option3 to display dialog "Good Evening"
set option4 to display dialog "Good Night"
set thelist to {"Dialog Box 1", "Dialog Box 2", "Dialog Box 3", "Dialog Box
4"}
set theDialog to choose from list thelist
repeat with i from 1 to (count thelist)
if item 1 of theDialog = item i of thelist then
set num to i
end if
end repeat
(option & num) as variable
And I know there are string to variable conversions out there, it's just
that's a ton of code. So does anyone have a good solution to this problem?
PS: Upon writing this e-mail I came across another annoyance of mine. How
come I have to use a repeat loop to determine what item number my value is?
Is there a command that I don't know about that does something like this:
Item "Dialog Box 1" of the_list
(and yes I know AppleScript lists don't work that way... But it would be
nice.)
Thanks!
Stephen Swift
email@hidden
-----------------------------------------------
AppleScript Guru - The Mac Observer
http://www.macobserver.com/tips/applescript
_______________________________________________
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.