Posted on March 12, 2008 at 10:17 pm

AppleScript Dictionaries

In our first script, we commanded the computer to “say” “Hello from AppleScript”. We also learned that, in AppleScript, you “tell” your applications to do things using commands. Looking closer at this example, you’ll notice that we didn’t “tell” any particular application to say “Hello from AppleScript”. That’s because AppleScript allows developers to not only write AppleScript-capable applications, but also extensions to AppleScript called “scripting additions” or OSAXen. Scripting additions provide additional commands for your use. Apple provides a scripting addition called “Standard Additions” that includes many useful commands including “say”. If you do not tell a specific application to do something, then AppleScript will look for the command in the scripting additions installed on your computer. In our first script, we did not tell the computer what to do, so AppleScript looked through our scripting additions and found the “say” command in the scripting addition called “Standard Additions”.

#### Finding commands

So how to we find these commands? We look them up in a dictionary! Developers who implement AppleScript in their applications create AppleScript dictionaries that show all of the commands available to that application (or scripting addition). You can reveal a dictionary in Script Editor by clicking File > Open Dictionary…

A dialog will appear as shown below with a list of applications and scripting additions available for use.

Open Dictionary dialog

The dialog shows all applications that have dictionaries, including scripting additions and applications that do not have a graphical user interface. Scroll down the list of applications, select “Standard Additions”, then click “OK”. Script Editor will open the Standard Additions dictionary and display it on your screen:

Standard Additions

The dictionary viewer resembles column view in the Finder and works the same way. In the leftmost column, you will see a list of several categories including “User Interaction”. Select that category and a new list of terms will appear in the next column. The first item in the list shows a blue box with the letter “C” in white, followed by the word “beep”. The “C”-in-a-box means that the word following the “C”-in-a-box is a “command”. Because the word “beep” follows the “C”-in-a-box, “beep” is a command. What does “beep” do? It makes your computer beep! Try it in Script Editor. Type “beep” and then press Control+R. You’re computer just beeped at you.

Now scroll down that column and select the “say” command. Underneath the column view is a text view that gives more information about the “say” command. The first line reads: “say v: Speak the given text”. The first line usually gives a brief description of the command. The remaining text deals with the arguments to the “say” command. “Arguments?” I hear you say, “What are arguments?” The subject of the next post!

#### Extra! Extra!

From time to time, I’ll post extra bits in the extended post. This extended posts concerns commands. AppleScript provides four types of commands: an AppleScript command, a scripting addition command, a user-defined command, and an application command. We will learn about all of these commands, except user-defined commands. The “say” command is a scripting addition command because the command is implemented in a scripting addition. Easy enough. An application command is targeted at an application and these commands typically require a “tell” statement. An AppleScript command is one of five commands built into the AppleScript language: get, set, count, copy, and run. Please don’t memorize those commands. You have better things to do.

3 Responses to “AppleScript Dictionaries”

  1. Leigh Cowden on March 13th, 2008 at 7:33 says:

    I have been following the lessons and find them fascinating. I can’t wait to see what you show next. I’m excited to think I could add some functionality to my existing programs, or perhaps even get them talking to each other! Thanks Larry!

  2. Kevin Morton on March 13th, 2008 at 9:53 says:

    Larry:

    I can’t read the site in IE 6.0 (I’m at work.) It seems to have a Leopardesque background that has a black gradient in the lower half of the screen so that the text disappears into the darkness. Have you tested this?

    Probably fine on Safari.

    BTW, I’m with Leigh. Really looking forward to learning more about Applescript.

    Kevin

    J. Kevin Morton, Attorney
    1604 W. First Street
    Winston-Salem, NC 27104
    (336) 725-0700
    (336) 725-5934 (fax)
    jkm@mac-lawyer.com

  3. Larry Staton Jr. on March 13th, 2008 at 10:30 says:

    Kevin -

    IE6 does not properly support CSS2, so the white background does not appear. You can, of course, subscribe to my feed and read the site through your feed reader: http://feeds.feedburner.com/ScriptingForLaywers/

Leave a Reply