[ Home | Prev | Next ]

Chapter 5


Scripting Other Applications

One of Frontier's major strengths is its ability to work with other applications. It can interact with external applications in two basic ways: In this chapter, we will focus on how to write UserTalk scripts that take advantage of scriptable applications. We will begin by describing at a high level how your UserTalk scripts can "drive" an application. Then we'll build a couple of examples of such scripts. These sample scripts enable you to control a scriptable application called BarChart that is included in the UserLand Utilities Folder.

Of course, BarChart is just used as an example. You probably have many scriptable applications on your disk. This chapter will focus on the basics, giving you a foundation from which to learn the specifics of whichever applications are of particular interest to you.

How Scripts Control Programs

Frontier can control any program which is scriptable, that is, any program which has been written or enhanced to receive specific Apple event messages. Each application implements a different set of verbs, though similar applications often have many verbs in common.

Applications that are scriptable will generally come with a Frontier install file -- usually named something like BarChart.Frontier (the application name appearing before the period following "Frontier"). When you install the application for the first time, you will simply double-click on this install file. It will then install a table of verbs into Frontier's Object Database. Some install files may be available from sources other than the publisher of the application, including the Internet, on-line services and Macintosh user groups.

Figure 5-1 shows what actually happens when your UserTalk script instructs an external, scriptable application to do something which it "understands" (meaning that it has a corresponding verb or Apple event and an entry in the Frontier table where its interface is defined).


Figure 5-1. Controlling an Application from Frontier

Control One Application

Now that we know how an install script controls an application, how do we use them in our own UserTalk scripts? The short answer is that there is no fundamental difference between a UserTalk script that drives an external application and one that manipulates the Operating System or adds functionality to Frontier itself.

To use a verb connected to a scriptable application, you write a UserTalk script that:

To use a BarChart verb, then, you simply call it by providing the application's name, followed by a period, followed by the verb name, followed by a set of parentheses enclosing its parameters, if any.

Let's launch BarChart and take a look at one of its menus to see how we can use its verbs for a real task. Select "Launch BarChart" from the "Apps" sub-menu of the "Custom" menu in Frontier. The application will launch. Because BarChart supports a special Frontier protocol called "menu sharing," we can examine the scripts attached to its menus. In BarChart, hold down the Option key while you select "Folders on Each Disk" from the "Utilities" menu in BarChart. Hold the Option key down until Frontier opens the menubar editor for the menu, then click on the "Script" button. The resulting script looks like this:

As you can see, this menu option calls the volumeReport verb in BarChart and provides three arguments: the name of the window to open, the label string to be used on the bars in the graph, and the address of a verb to execute for each volume. (Passing the address of one verb as the parameter to another verb is an advanced technique sometimes referred to as a "callback". Details are beyond the scope of this manual.) If you're curious how this works, you can Command double-click on the last argument to open the file.foldersOnVolume verb or you can simply run the script by returning to BarChart and choosing the menu option. If you do run the script, the window will probably look something like Figure 5-4.


Figure 5-4. Sample BarChart Output from "Folders on Each Disk" Option

As you can see, using external applications from within Frontier is for all practical purposes as easy as using Frontier itself. As final proof, let's build a couple of useful examples that use BarChart and Doc Server.

Remember, we're using a UserLand-supplied program in these examples simply for convenience. There's nothing special about BarChart, it's just a scriptable application. The fundamental principles we'll be following in these examples apply to any scriptable software you want to control from UserTalk.

Contents Page | Next Section -- Integrate Multiple Applications
HTML formatting by Steven Noreyko January 1996, User Guide revised by UserLand June 1996