Let’s look again at the AppleScript dictionary entry for the “say” command.
The first line describes what the command does.
The second line reads, “say text: the text to speak, which can include intonation characters”. We’ll ignore the intonation characters for now, so let’s look at the part before the colon. “say” is the command. The word “text” is an argument of the command. A command such as “say” isn’t very useful without some words for the computer to speak. So AppleScript allows you to include “text” to make the “say” command useful. In our example, we wrote the text “Hello from AppleScript”. This text is called an argument, or parameter, of the command. Not all commands have parameters, so you must look at the dictionary to determine which commands require parameters. Now let’s look at the part of the line to the right of the colon, “the text to speak”. This statement describes what the parameter means to the command. In our example, the parameter “Hello from AppleScript” means “the text to speak”. When reading a dictionary, then, you would know that the parameter “text” when used with the “say” command means “the text to speak”.
Looking at line three, we see: “[displaying text]: the text to display”. This line looks similar to the second line except for the brackets []. The bold word inside the brackets is an additional command that can be used in conjunction with the “say” command. As above, the word following our command is a parameter. And the phrase following the colon describes what the parameter means to the command. So what does the bracket mean? The bracket means that this additional command is optional. You do not have to include the command “displaying” with text for the command to run properly. You know this is true because in our first script, we did not use any additional commands.
The “say” command has three more additional commands: using text, waiting until completion boolean, and saving to any. Let’s take a closer look at [using text]. The description of text reads, “the voice to speak with.” Hmm. What does this mean? Unfortunately, the dictionary doesn’t tell you, but I will. Your Mac ships with several “voices” that you can use for your system and in your scripts. Open System Preferences, select the Speech Preference Pane, and click the “Text to Speech” tab. You should see a drop-down menu next to a label titled “System Voice”. If you click on the drop-down menu, you’ll see a list of voices that you can use. Let’s use “Victoria” in our script.
Fire up Script Editor (you already had it open, didn’t you?), and type the following:
say "Hello from AppleScript" using "Victoria"
Now click the “Run” button or type Command+R. You should hear a female voice—Victoria’s voice—speak to you this time. Cool!
In our next lesson, we’ll look more closely at the argument types such as “text” and “boolean”.
Leave a Reply