AppleScript Language Guide

AppleScript Language Guide

by Apple Computer Inc.

Paperback

$26.95 $29.95 Save 10% Current price is $26.95, Original price is $29.95. You Save 10%.

Temporarily Out of Stock Online

Eligible for FREE SHIPPING

Overview

AppleScript Language Guide by Apple Computer Inc.

This book is an essential reference for anyone using AppleScript to modify existing scripts or write new ones. It provides many sample scripts and discusses advanced topics such as writing command handlers for script applications, the scope of script variables and properties declared at different levels in a script, and inheritance and delegation among script objects.

Product Details

ISBN-13: 9780201407358
Publisher: Addison-Wesley
Publication date: 02/28/1994
Pages: 416
Product dimensions: 7.52(w) x 9.04(h) x 0.88(d)

First Chapter

Chapter One

Introduction

AppleScript is a scripting system that allows you to directly control Macintosh applications, including the Mac OS itself. Instead of using a mouse, keyboard, or other input device to manipulate menus, buttons, and other interface items, you can create sets of written instructions-known as scripts-to automate repetitive tasks, customize applications, and even control complex workflows.

This document is a complete guide to the AppleScript language. It is intended for use with AppleScript version 1.3.4 or later and Mac OS 8.5.1 or later, although some descriptions and examples may work with earlier versions.

This version of the AppleScript Language Guide has been revised to cover new features in AppleScript, to include examples from the Mac OS and the Finder, to improve formatting for online viewing, and to correct errors. For a detailed listing of the changes, see "Document Revision History" (page 391).

This guide should be useful to anyone who wants to write new AppleScript scripts or modify existing scripts. If you are new to AppleScript, however, you might want to start by reading the AppleScript section of the Mac OS Help Center, or by reviewing the introductory materials at the AppleScript website:

http://www.apple.com/applescript/

You can also find introductory books on AppleScript at many bookstores and online sites. Macintosh software developers who want to create scriptable applications should refer to Inside Macintosh: Interapplication Communication, and to related information available at the Apple Developer website:

http://www.apple.com/developer/

This guide describes the AppleScript language in thefollowing chapters:

  • "Overview of AppleScript" (page 19) introduces AppleScript and its capabilities and provides an overview of the elements of the AppleScript language. Introduction

  • "Values and Constants" (page 51) describes AppleScript's value classes, predefined constants, and coercions for converting between value classes.

  • "Commands" (page 109) describes the commands available in AppleScript.

  • "Objects and References" (page 161) describes objects and their characteristics and explains how to refer to. objects in scripts.

  • "Expressions" (page 199) describes AppleScript expressions, the operators they use, and how they're evaluated.

  • "Control Statements" (page 237) describes statements that control when and how other statements are executed.

  • "Handlers" (page 279) describes subroutines, command handlers, error handlers, and the scope of variables and properties in handlers and elsewhere in a script.

  • "Script Objects" (page 325) describes how to define and use script objects.

  • "The Language at a Glance" (page 349) provides a quick overview of the AppleScript language. It includes a table with links to examples of common scripting tasks.

  • "Document Revision History" (page 391) provides a history of changes to this document.

Most sample scripts in this guide demonstrate scriptable features of the Finder, the Mac OS, or applications distributed with the Mac OS, such as the Apple System Profiler. Some examples use AppleWorks, an application suite available from Apple Computer, Inc.

Table of Contents

Figures and Tables ..... 13

Chapter 1 Introduction ..... 17

Chapter 2 Overview of AppleScript ..... 19

Conventions Used in This Guide ..... 20
What Is AppleScript? ..... 21
How AppleScript Works ..... 29
Statements ..... 31
Commands and Objects ..... 32
Dictionaries ..... 34
Values and Constants ..... 36
Expressions ..... 37
Script Objects ..... 39
Scripting Additions ..... 40
Dialects ..... 40
Other Features and Language Elements ..... 41
Abbreviations ..... 46
Compiling Scripts With the Script Editor ..... 47
Debugging Scripts ..... 47

Chapter 3 Values and Constants ..... 51

Using Value Class Definitions ..... 52
Common Value Class Definitions ..... 56
Unicode Text and International Text ..... 87
Unit Type Value Classes ..... 91
Other Value Classes ..... 94
Coercing Values ..... 97
Constants ..... 100

Chapter 4 Commands ..... 109

Types of Commands ..... 110
Using Command Definitions ..... 115
Using Parameters ..... 118
Using Results ..... 121
Double Angle Brackets in Results and Scripts ..... 123
Command Definitions ..... 127

Chapter 5 Objects and References ..... 161

Object Class Definitions ..... 162
References ..... 165
Reference Forms ..... 169
Using the Filter Reference Form ..... 187
References to Files and Applications ..... 190

Chapter 6 Expressions ..... 199

Results of Expressions ..... 200
Variables ..... 200
Script Properties ..... 208
AppleScript Properties ..... 210
Reference Expressions ..... 212
Operations ..... 213
Contains, Is Contained By ..... 227
Concatenation 229 .....
Operator Precedence ..... 231
Date-Time Arithmetic ..... 233
Working With Dates at Century Boundaries ..... 235

Chapter 7 Control Statements ..... 237

Characteristics of Control Statements ..... 238
Debugging Control Statements ..... 239
Tell Statements ..... 240
If Statements ..... 245
Repeat Statements ..... 249
Try Statements ..... 259
Considering and Ignoring Statements ..... 268
With Timeout Statements ..... 272
With Transaction Statements ..... 275

Chapter 8 Handlers ..... 279

Script Applications ..... 279
About Subroutines ..... 280
Defining and Calling Subroutines ..... 289
Subroutines With Labeled Parameters ..... 290
Subroutines With Positional Parameters ..... 296
Command Handlers ..... 300
Scope of Script Variables and Properties ..... 311
Scope of Properties and Variables Declared at the Top Level of a script ..... 313
Scope of Properties and Variables Declared in a Script Object ..... 316
Scope of Variables Declared in a Handler ..... 321

Chapter 9 Script Objects ..... 325

About Script Objects ..... 326
Defining Script Objects ..... 327
Sending Commands to Script Objects ..... 328
Initializing Script Objects ..... 329
Inheritance and Delegation ..... 331
Using the Copy and Set Commands With Script Objects ..... 342

Appendix A The Language at a Glance ..... 349

Common Scripting Tasks ..... 350
Constants ..... 354
Predefined Variables ..... 358
Commands ..... 359
Coercions ..... 363
References ..... 365
Operators ..... 367
Control Statements ..... 373
Handlers ..... 376
Script Objects ..... 378
Variable and Property Assignments and Declarations ..... 378
Placeholders ..... 380
Error Numbers and Error Messages ..... 384

Appendix B Document Revision History ..... 391

Glossary ..... 395
Index ..... 405

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews