Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [238]

By Root 1574 0
where you'll ask to have your code turned into a real application (called building the project). What makes your project an AppleScript Studio application is that you specify "AppleScript Application" when you create the project.

The fact that you design your interface in one application but edit your code and build the application in another is a tricky aspect of the Cocoa development experience, and takes some getting used to. As a beginner, you should work on only one project at a time; while doing so, keep both Interface Builder and Xcode running but hide whichever you're not using at that moment.

Tutorial

There is a hands-on tutorial at /Developer/ADC Reference Library/documentation/AppleScript/Conceptual/StudioBuildingApps/. I have reservations about its appropriateness (it employs some techniques I regard as inadvisable), but it's probably worth going through it, if only as a way of becoming familiar with Xcode and Interface Builder.

Reference

The most important AppleScript Studio documentation is the reference document at /Developer/ADC Reference Library/documentation/AppleScript/Reference/StudioReference/. You should skim through this at the outset and then expect to refer to it constantly while working.

The dictionary

The terminology for the repertory of things you can say in an AppleScript Studio application is defined in a dictionary. (You don't have to target any application in your AppleScript Studio code in order to gain access to this terminology; it is made automatically available.) This dictionary appears in your project as AppleScriptKit.sdef; double-click it to view it in a dictionary display. This is essentially the same information as in the reference, but not as well presented, so you're less likely to use it.

Examples

There are many AppleScript Studio examples located in /Developer/Examples/AppleScript Studio. They explore and demonstrate most of the important aspects of using AppleScript Studio to drive the user interface; it's very worthwhile to study them.

Cocoa documentation

There are good links to help you find your way into Cocoa, Objective-C, and Cocoa documentation in an introductory document at /Developer/ADC Reference Library/referencelibrary/GettingStarted/GS_Cocoa/. Furthermore, each page about an AppleScript class in the AppleScript Studio reference document is cross-linked to the page about the corresponding Cocoa class; the discussion of the Cocoa class is well worth consulting, as it often explains things better, and frequently has links to even more useful pages on general topics about how things work in Cocoa.

AppleScript Studio Example


As a tutorial example, let's return to the code presented earlier for searching the TidBITS online archive (in Chapter 25). Recall what it does. We allow the user to enter search terms. We use curl to submit those terms to the TidBITS search engine. The reply is a page of HTML listing the pages found. We use Perl to parse the HTML, and present the results to the user as a list. If the user double-clicks a listed article, we present the corresponding page in the web browser. The purpose of the tutorial is to illustrate AppleScript Studio development by wrapping this script in a nice interface. We'll have two windows, a Search window where the user enters search terms and a Results window where the results will be listed.

Begin by creating the project. Start up Xcode. Choose File → New Project and select "AppleScript Application"; in the dialog that appears, name the project SearchTidBITS and finish creating it.

We must embed the Perl script into the bundle of the built application. This must be done by the build process, so the Perl script must be incorporated into the project. Select the Resources folder on the left side of the project window and choose Project → Add Files. In the Open File dialog, find and select the Perl script, which is called parseHTML.pl. In the next dialog, check the box at the top which asks whether you want to copy the file into the project, and click the Add button.

Now we'll design the interface.

Return Main Page Previous Page Next Page

®Online Book Reader