Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [237]

By Root 1447 0
of interpreter between Cocoa and your AppleScript code. The interpreter's job is to take care of all the differences between Cocoa and AppleScript, so that you don't have to worry about them. Cocoa sends out a delegation query or a notification message; the interpreter receives this and turns it into AppleScript and routes an appropriate event handler call to your script. Your AppleScript code obtains references to interface elements and targets them with commands, and gets and sets their properties; the interpreter turns this into Objective-C and calls the corresponding built-in method of the relevant Cocoa object. This interpreted linkage between AppleScript and Cocoa is often referred to as a bridge, and we say that the Apple folks have bridged AppleScript to (certain parts of) Cocoa.

The first thing to do in learning AppleScript Studio is to consider learning more about Cocoa. After all, AppleScript Studio is Cocoa, and even if you'd rather not learn any Objective-C, it can be really helpful to have some familiarity with the location of the Cocoa documentation on your hard drive, and perhaps to read a couple of good introductory Cocoa books. (My favorite is Aaron Hillegass, Cocoa Programming for Mac OS X [Addison-Wesley, 2004], 2nd ed.) Furthermore, it's possible that you might end up wanting to learn some Objective-C after all. You can easily find your programming desires thwarted when you encounter an area where AppleScript is not bridged to Cocoa. There are four solutions when this happens:

Give up

If you restrain your desires, your desires can't be thwarted. If something you want to do isn't bridged, stop wanting to do it and confine yourself to what is bridged. This is not an ignoble way out; all programming involves a trade-off of time and effort, and it may be that simplifying your needs is the wisest course.

Use call method

You can call directly from AppleScript into an Objective-C method with the call method command (I'll illustrate its use later on).

Make a hybrid

It's perfectly possible for some of your code to be written in AppleScript, in a script, and for other parts of your code to be written in Objective-C, in a custom class. In effect, such an application is a hybrid of Objective-C/Cocoa and AppleScript Studio.

Give up, the other way

Sometimes AppleScript in Cocoa is a square peg in a round hole. Consider learning Objective-C and writing your application in Objective-C/Cocoa. You can still use AppleScript from within Objective-C (see "Application" in Chapter 2). It may seem paradoxical, but not using AppleScript Studio can sometimes be the wisest development strategy.

The Pieces of AppleScript Studio


AppleScript Studio is like Los Angeles: it isn't actually anywhere. It isn't a thing or a place; it's many tools and resources, used in a certain way. Let's talk about those tools and resources.

The developer tools

The developer tools, collectively known as the Xcode Tools, are on the Tiger DVD, but they are an optional installation. If you don't install them, you won't have any of the AppleScript Studio tools and resources on your hard disk. So install them! An even better approach, as the version on your copy of the Tiger DVD may be outdated, is to obtain the latest version from Apple. First you must join the Apple Developer Connection ; the "online" membership level is free (http://developer.apple.com/membership/online.html). Then you'll be able to log in and download the Xcode Tools .

Interface Builder

Interface Builder, an application located (after you've installed the developer tools) in /Developer/Applications, is where you'll design your application's interface. It's worth perusing the Interface Builder Help early in the game.

Xcode

The Xcode application (not to be confused with the Xcode Tools as a whole) is also in /Developer/Applications. This is where you create and work with a project (the collection of files that will be combined to create your application); it's where you write your code, it's where you access the files that constitute the project, and it's

Return Main Page Previous Page Next Page

®Online Book Reader