• 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
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Choose from list


  • Subject: Re: Choose from list
  • From: Paul Berkowitz <email@hidden>
  • Date: Sun, 05 May 2002 17:38:25 -0700

On 5/5/02 4:21 PM, "Stephen Swift" <email@hidden> wrote:

> 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

One way:

set theList to {"Dialog Box 1", "Dialog Box 2", "Dialog Box 3", "Dialog Box
4"}

set optionList to {"Good Morning", "Good Afternoon", "Good Evening", "Good
Night"}

set theDialog to choose from list theList

repeat with i from 1 to 4
if theDialog is {(get (item i of theList))} then
display dialog (item i of optionList)
exit repeat
end if
end repeat



Another is really the same thing, but keeping a routine handy for doing the
work, then just call the routine (there are ways to protect against
non-items and to speed things up for large lists, but this is the simple
version to begin with):



set theList to {"Dialog Box 1", "Dialog Box 2", "Dialog Box 3", "Dialog Box
4"}

set optionList to {"Good Morning", "Good Afternoon", "Good Evening", "Good
Night"}

set theDialog to (choose from list theList) as string

set x to my UniqueIndex(theList, theDialog)

display dialog (item x of optionList)

on UniqueIndex(aList, anItem)
repeat with i from 1 to (count aList)
if anItem = item i of aList then
return i
end if
end repeat
end UniqueIndex




--
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.

  • Follow-Ups:
    • Re: Choose from list
      • From: Stephen Swift <email@hidden>
References: 
 >Choose from list (From: Stephen Swift <email@hidden>)

  • Prev by Date: Copying files into packages
  • Next by Date: Re: Choose from list
  • Previous by thread: Copying files into packages
  • Next by thread: Re: Choose from list
  • Index(es):
    • Date
    • Thread