Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Recent issues

Article Preview


Buy Now

Issue 1.5

COLUMN

AppleScriptable Applications

Creating an 'aete' resource and interpreting AppleEvents

Issue: 1.5 (April/May 2003)
Author: Thomas Reed
Author Bio: Thomas Reed has been programming as a hobbyist for more than 20 years, and fell in love with the Mac in 1984.
Article Description: No description available.
Article Length (in bytes): 10,785
Starting Page Number: 30
Article Number: 1515
Resource File(s):

Download Icon 1515.zip Updated: 2013-03-11 19:07:56

Related Web Link(s):

http://www.panix.com/~gmcgath/EightyRez.html

Excerpt of article text...

Given the choice between a program that supports AppleScript and a similar one that does not, many people will choose the program that is scriptable. Because of this, it is clearly advantageous to create an AppleScript interface for your application. It is a common misconception that writing scriptable applications is very difficult. This article will provide an introduction to creating AppleScript interfaces that will help dispel this myth.

AppleScripts work by translating English-like language into AppleEvents, which are then sent to the target application. Thus, there are two main aspects of AppleScripting that must be managed. First, your application must provide an AppleEvent Terminology Resource, which defines the AppleScript commands it understands. Second, you must interpret any AppleEvents sent to your application and invoke the requested behavior.

An AppleEvent Terminology Resource is a resource of type 'aete' and ID 0. It defines the various events and classes that your application understands, providing a translation from AppleScript to AppleEvents. For this article, I will describe how to create 'aete' resources using a free 'aete' editor called EightyRez, which only runs under Classic and is available from http://www.panix.com/~gmcgath/EightyRez.html.

Once you have decided exactly which functions and data you want to make available through the AppleScript interface, you can create an 'aete' resource. The sample application for this article (see download instructions on page 4), called ArbieText, allows the user to create an arbitrary number of windows, each of which can contain user-specified text. For this application, it is logical to make the number of windows, the name of each window, and the text contained in each window accessible via AppleScript.

The first thing you need to do in EightyRez is to create a new resource file (File -> New). Next, create a new event suite in the 'aete' resource (aete -> New Suite). For our example, we'll use 'RBtx' as the suite ID and "ArbieText Suite" as the suite name. You should also set the Level, as defined by Apple, to 1.

You can start creating your custom events once you have defined a suite to contain them. We'll start with the easiest, WindowCount, which will obtain the number of windows open in ArbieText. Select the ArbieText suite and create a new event (aete -> New Event). The event ID can be anything you like; for this example we'll choose 'WCnt'. The event's class should be the same as the ID of the suite containing it, and you should enter WindowCount as the name. Set the reply type field to 'long' (typeInteger in the pop-up menu next to the field), indicating that the reply to the WindowCount event will contain a long integer. The various description fields will be displayed when a user views your application's script dictionary, but have no other meaning than that. To include the 'aete' resource in your application, click OK, save the file, and add it to your project.

...End of Excerpt. Please purchase the magazine to read the full article.