AppleScript Language Guide.pdf

(2230 KB) Pobierz
AppleScript Language Guide
AppleScript Language Guide
Scripting & Automation > AppleScript
2008-03-11
650799696.002.png
Apple Inc.
© 2008 Apple Inc.
All rights reserved.
TimesisaregisteredtrademarkofHeidelberger
Druckmaschinen AG, available from Linotype
Library GmbH.
Simultaneously published in the United States
and Canada.
Even though Apple has reviewed this document,
APPLEMAKESNOWARRANTYORREPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
THIS DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY,ORFITNESSFORAPARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS
PROVIDED “AS IS,” AND YOU, THE READER, ARE
ASSUMING THE ENTIRE RISK AS TO ITS QUALITY
AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIALDAMAGESRESULTINGFROMANY
DEFECTORINACCURACYINTHISDOCUMENT,even
if advised of the possibility of such damages.
THEWARRANTYANDREMEDIESSETFORTHABOVE
AREEXCLUSIVEANDINLIEUOFALLOTHERS,ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple
dealer, agent, or employee is authorized to make
any modification, extension, or addition to this
warranty.
Somestatesdonotallowtheexclusionorlimitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusionmaynotapplytoyou.Thiswarrantygives
you specific legal rights, and you may also have
other rights which vary from state to state.
Nopartofthispublicationmaybereproduced,
stored in a retrieval system, or transmitted, in
any form or by any means, mechanical,
electronic, photocopying, recording, or
otherwise, without prior written permission of
Apple Inc., with the following exceptions: Any
person is hereby authorized to store
documentation on a single computer for
personal use only and to print copies of
documentation for personal use provided that
thedocumentationcontainsApple’scopyright
notice.
The Apple logo is a trademark of Apple Inc.
Use of the “keyboard” Apple logo
(Option-Shift-K) for commercial purposes
withoutthepriorwrittenconsentofApplemay
constitute trademark infringement and unfair
competition in violation of federal and state
laws.
No licenses, express or implied, are granted
withrespecttoanyofthetechnologydescribed
in this document. Apple retains all intellectual
propertyrightsassociatedwiththetechnology
described in this document. This document is
intended to assist application developers to
develop applications only for Apple-labeled
computers.
Every effort has been made to ensure that the
informationinthisdocumentisaccurate.Apple
is not responsible for typographical errors.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
.Mac is a registered service mark of Apple Inc.
Apple,theApplelogo,AppleScript,AppleScript
Studio, AppleShare, AppleTalk, Bonjour, eMac,
iTunes, iWork, Leopard, Logic, Mac, Mac OS,
and Macintosh are trademarks of Apple Inc.,
registered in the United States and other
countries.
Finder,Numbers,andSpotlightaretrademarks
of Apple Inc.
Intel and Intel Core are registered trademarks
of Intel Corportation or its subsidiaries in the
United States and other countries.
650799696.003.png
Contents
Introduction Introduction to AppleScript Language Guide 13
Who Should Read This Document? 14
Organization of This Document 14
Conventions Used in This Guide 15
See Also 16
Chapter 1
AppleScript Lexical Conventions 17
Character Set 17
Identifiers 18
Keywords 18
Comments 19
The Continuation Character 20
Literals and Constants 20
Boolean 20
Constant 20
List 21
Number 21
Record 21
Text 21
Operators 22
Variables 22
Expressions 22
Statements 23
Commands 23
Results 24
Raw Codes 24
Chapter 2
AppleScript Fundamentals 25
Script Editor Application 25
AppleScript and Objects 26
What Is in a Script Object 27
Properties 28
Elements 28
Object Specifiers 29
What Is in an Object Specifier 29
Containers 30
Absolute and Relative Object Specifiers 30
Object Specifiers in Reference Objects 31
Coercion (Object Conversion) 32
2008-03-11 | © 2008 Apple Inc. All Rights Reserved.
3
650799696.004.png
CONTENTS
Scripting Additions 34
Commands Overview 34
Types of Commands 35
Target 35
Direct Parameter 36
Parameters That Specify Locations 36
AppleScript Error Handling 36
Global Constants in AppleScript 37
AppleScript Constant 37
current application Constant 39
missing value Constant 40
true, false Constants 40
The it and me Keywords 40
Aliases and Files 41
Specifying Paths 42
Working With Aliases 42
Working With Files 43
Remote Applications 44
Enabling Remote Applications 44
eppc-Style Specifiers 44
Targeting Remote Applications 44
Debugging AppleScript Scripts 45
Feedback From Your Script 45
Logging 46
Third Party Debuggers 46
Chapter 3
Variables and Properties 47
Defining Properties 47
Declaring Variables 48
Local Variables 48
Global Variables 49
Using the copy and set Commands 49
Scope of Variables and Properties 51
Scope of Properties and Variables Declared in a Script Object 52
Scope of Variables Declared in a Handler 55
Chapter 4
Script Objects 57
Defining Script Objects 57
Initializing Script Objects 59
Sending Commands to Script Objects 59
Inheritance in Script Objects 60
The AppleScript Inheritance Chain 60
Defining Inheritance Through the parent Property 61
Some Examples of Inheritance 61
4
2008-03-11 | © 2008 Apple Inc. All Rights Reserved.
650799696.005.png
CONTENTS
Using the continue Statement in Script Objects 63
Chapter 5
About Handlers 67
Handler Basics 67
Defining a Simple Handler 68
Handlers with Labeled Parameters 68
Handlers with Positional Parameters 69
Handlers with Patterned Positional Parameters 70
Recursive Handlers 71
Errors in Handlers 71
Passing by Reference Versus Passing by Value 71
Calling Handlers in a tell Statement 72
Saving and Loading Libraries of Handlers 72
Handlers in Script Applications 73
run Handlers 74
open Handlers 75
idle and quit Handlers for Stay-Open Applications 76
Calling a Script Application From a Script 77
Chapter 6
Class Reference 79
alias 79
application 80
boolean 82
class 83
constant 84
date 85
file 88
integer 89
list 89
number 92
POSIX file 93
real 93
record 94
reference 95
RGB color 96
script 97
text 97
unit types 103
Chapter 7
Commands Reference 105
activate 108
ASCII character 108
ASCII number 109
2008-03-11 | © 2008 Apple Inc. All Rights Reserved.
5
650799696.001.png
Zgłoś jeśli naruszono regulamin