AppleScript dialog lists - how to display a list in a dialog

AppleScript dialog list FAQ: How can I display a list in an AppleScript dialog?

I couldn't find an example showing how to display a list of strings in an AppleScript dialog, so I created the following simple example. First I create a list (in this case a short list of voices on Mac OS/X that can be used with the say command), and then I display the list in a dialog the user can use to select one of the items in the list.

--
-- a sample AppleScript program to prompt a user to select an item from a list
--

-- display a dialog to prompt the user to select a voice from a list of voices
set myVoices to {"Agnes", "Kathy", "Princess", "Vicki", "Victoria"}

-- get the voice the user selected from the list
set selectedVoice to {choose from list myVoices}

-- say "Hello world" using the voice the user selected
say "Hello world" using selectedVoice

AppleScript dialog list - Sample image

Here's what this AppleScript list dialog looks like:

An AppleScript dialog displaying a list.

At the moment I'm new to AppleScript, but I personally don't like using syntax like this:

display dialog "What should I say?" default answer ""

to display a dialog prompting a user to enter some text, and significantly different syntax like this:

choose from list myVoices

to display a dialog prompting the user to select an item from a list. I know that the intent is to make the language very human-readable, but I'd prefer more consistency here.

In a related note, if you want to make your AppleScript dialog list look better, here's a link to my Customize your AppleScript dialog tutorial.

In a related note, here's a link to my semi-famous Mac text to speech using AppleScript tutorial. It's similar to this tutorial, but reads several different Mac OS X voices one after the other, so you can get an idea of what all the voices sound like.

Post new comment

The content of this field is kept private and will not be shown publicly.