Last updated: 8/4/98
Architecture
Applications such as FileMaker, Finder, ClarisWorks can support AppleScript in three ways and to different levels.Scriptable
A script can be written to control certain procedures and settings of the application. The application can be dropped onto the Script Editor to see its dictionary of understood commands, objects and properties.Recordable
An application can be Scriptable by just supporting the standard suite (open, close, print, quit), but that doesn't allow you to automate any useful operations. The Finder, FileMaker and Excel are among the most Scriptable applications. But they have limits. For instance, you cannot currently tell the Finder to log into a file server (without a scripting addition) and you can't tell FileMaker to define a new field. Other applications which are less Scriptable sometimes have work arounds by letting you call their in-built macros or menus. For example, you can create a macro in ClarisWorks, Word 6 or FoxPro and then AppleScript can "do script" to execute the macro.
When recording is turned on on the Script Editor, actions performed by the user in the application are written as AppleScript commands in the Script Editor's window.Attachable
An application must be scriptable to some degree before it can be recordable. If recordable, AppleScript can write a lot of your script for you as you simply use the application. For instance, with recording on, you can copy a file in the Finder, open it in Excel, parse it and save it, having the whole process recorded. A recorded script only contains commands. To really exploit AppleScript, you usually want to add parameter setting and getting and decisions (if then, repeat, etc) to make it more robust. Applications which are mostly scriptable include the Finder, Scriptable Text Editor, and many Internet client applications such as Fetch and Eudora. Excel 4, ClarisWorks, FileMaker, WordPerfect, HyperCard, Navigator and Explorer are scriptable but not recordable. There are many others.
Events in the application can be trapped to launch a script. For example, when the user chooses a menu, clicks an icon or moves a drawing a script can be activated.
Attachable applications are unfortunately rare and the level of support varies. Attachable applications include Finder, HyperCard, FileMaker 3.0, ClarisWorks Office 5 and FaceSpan. You can assign a script to an object like a button, icon or menu, executing once clicked, moved or whatever. You can save scripts as applications in the Finder so they execute when double clicked, or accessed somewhere in the Apple menu. HyperCard and FaceSpan allow you to assign scripts to buttons and just about every other interface object.
There are several AppleScript editors on the market such as Script Editor (free with AppleScript from Apple), FaceSpan (which incorporates user interface building), Script Wizard, Script Debugger, and other non specialised applications which have some AppleScript editing support such as FileMaker 3.0.
Script Editors typically allow you to:
- View an application or OSAX dictionary.
- Turn recording on/off.
- Compile the script.
- Run the script.
- Show the result.
- Show the event log.
- Save as an application.
- Save as a read only application
- Open a non read only applet by dropping it onto the editor's icon.
AppleScript is part of the standard MacOS installation since 7.5 . It incorporates some Scripting Additions (OSAX). If you see redraw bugs with multiple styles in a script on PowerMacs, then you should trash the WorldScript Power extension. It can useful to install the AppleScript AppleGuide for quick reference. The FaceSpan extension is required to run FaceSpan mini applications or the FaceSpan application. AppleScript runs on any Mac. FaceSpan requires a 68020 or better. The Scriptable Text Editor comes as part of Speech recognition and some other packages.
An application's (or OSAX's) objects and events are shown in its dictionary in the Script Editor. To see an application's dictionary, just drop it onto the Script Editor icon.
AppleScript uses the Apple Object Model to refer consistently to objects within applications. For example, to refer to a file in the Finder:
file "my file" of folder "big folder" of folder "small folder" of disk "my disk" of application "Finder"
or in the Scriptable Text Editor:
word 1 of paragraph 3 of document "my essay" of application "Scriptable Text Editor"
Objects exist in other objects and ultimately in an application. When referring to a series of objects within the same outer object, it is easier to wrap all the references inside a tell structure, eg:
tell application "Finder"
file "my file" of folder "big folder" of folder "small folder" of disk "my disk"
file "my other file" of folder "another folder" of disk "another disk"
end tell
or
tell folder "my folder" of disk "my disk" of application "Finder"
file "my file"
file "another file in same folder"
end tell
AppleScript commands are converted internally to high level Apple Events. Events are verbs or actions. Each application has its own suite of events which appear as plain text in the Script Editor Dictionary. Most applications have similar events such as delete, duplicate, make. AppleScript itself only has a few commands, and the most commonly used is set. The complete AppleScript Syntax is listed here.
An AppleScript script has almost no user interface (buttons, menus etc) but uses little memory for a basic program and can interact easily with many applications, even on another networked Mac.
If a user interface is required, then you can use an OSAX, such as display dialog, tell an application to display some text or buttons (if the application supports those actions), or build the application in an GUI editor such as FaceSpan or HyperCard.
In FaceSpan, you can create windows, menus, buttons etc all with associated scripts. You can add in OSAXen, pictures, movies and so on. It has some quite sophisticated elements like tables (like a spreadsheet) and drag-and-drop support. You can create a standalone application and distribute it royalty free.
Return to Parent Folder