Sanderson / Rosenthal / Piper | Learn AppleScript | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 1104 Seiten

Sanderson / Rosenthal / Piper Learn AppleScript

The Comprehensive Guide to Scripting and Automation on Mac OS X
3rd ed
ISBN: 978-1-4302-2362-7
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

The Comprehensive Guide to Scripting and Automation on Mac OS X

E-Book, Englisch, 1104 Seiten

ISBN: 978-1-4302-2362-7
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



AppleScript is an English-like, easy-to-understand scripting language built into every Mac. AppleScript can automate hundreds of AppleScript-able applications, performing tasks both large and small, complex and simple. Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition has been completely updated for Mac OS X Snow Leopard. It's all here, with an emphasis on practical information that will help you solve any automation problem-from the most mundane repetitive tasks to highly integrated workflows of complex systems. Friendly enough for beginners, detailed enough for advanced AppleScripters Includes major contributions from expert AppleScripters: Emmanuel Levy, Harald Monihart, Ian Piper, Shane Stanley, Barry Wainwright, Craig Williams, and foreword by AppleScript inventor, William Cook

Hamish Sanderson is a ten-year veteran of AppleScript and professional automation developer living and working in the U.K. Over the years, he has contributed a range of useful libraries and utilities to the AppleScript community and pops up with some regularity on the various AppleScript mailing lists. He is also the author of the highly regarded Appscript library, which brings AppleScript-style application scripting support to the Python, Ruby, and Objective-C languages on Mac OS X.

Sanderson / Rosenthal / Piper Learn AppleScript jetzt bestellen!

Weitere Infos & Material


1;Title Page;1
2;Copyright Page;2
3;Contents at a Glance;3
4;Table of Contents;5
5;Foreword;19
6;About the Authors;21
7;About the Technical Reviewer;22
8;Acknowledgments;23
9;Introduction;24
9.1;If You Have Never Scripted Before…;24
9.2;If You Are Already an AppleScript User…;25
9.3;If You Are an Experienced Programmer…;26
9.4;Resources;27
9.5;Formatting Conventions Used in This Book;27
9.6;Errata;28
10;Part I Welcome to AppleScript;29
11;Chapter 1 Introducing AppleScript;30
11.1;Automating with AppleScript: From Small Tasks to Large;30
11.1.1;Automating Small Tasks;30
11.1.2;Automating Large Tasks;31
11.1.3;When to Automate (or Not)?;32
11.2;The Golden Triangle: Scriptable Applications, the AppleScript Language, and the Scripts You Write;33
11.2.1;What Is a Scriptable Application?;33
11.2.1.1;Introducing Objects;34
11.2.1.2;Introducing Commands;34
11.2.2;What Is the AppleScript Language?;35
11.2.3;What Is a Script?;36
11.3;Your First AppleScript: Hello World!;37
11.4;Summary;40
12;Chapter 2 AppleScript in Principle;41
12.1;The Four Key Concepts of Application Scripting;42
12.1.1;How Applications Represent Information As Objects;42
12.1.2;How Applications Manipulate Objects Using Commands;44
12.1.3;How Applications Organize Their Objects into Object Models;45
12.1.4;How Applications Describe Their Objects and Commands in Dictionaries;47
12.2;The Four Key Concepts of the AppleScript Language;48
12.2.1;How AppleScript Represents Information As Objects;49
12.2.2;How AppleScript Manipulates Objects Using Commands, Operators, and Variables;50
12.2.2.1;Using Commands;50
12.2.2.2;Using Operators;50
12.2.2.3;Using Variables;51
12.2.3;How AppleScript Makes Decisions on What to Do and When to Do It;51
12.2.4;How AppleScript Organizes Code Using Handlers and Script Objects;52
12.3;Tying It All Together: What Makes AppleScript Special;54
12.3.1;The English-like Syntax;54
12.3.2;Built-in Application Scripting Support;55
12.3.3;Attaching Scripts to Applications;55
12.3.4;The AppleScript Community;56
12.4;Summary;57
13;Chapter 3 AppleScript in Practice;58
13.1;The Project: Tidy Desktop;58
13.2;Planning the Script;59
13.3;Writing the Script;60
13.3.1;Creating the Folder Name;60
13.3.1.1;Getting Today’s Date As Text;60
13.3.1.2;Putting the Name Together;63
13.3.2;Interacting with the File System;64
13.3.2.1;Addressing the Finder;65
13.3.2.2;Creating the Archive Folder;67
13.3.2.3;Moving the Files;70
13.4;Final Thoughts;71
13.4.1;Improving Reliability;71
13.4.2;Adding Features;72
13.4.3;Documenting Your Code;73
13.5;Summary;74
14;Part II Understanding AppleScript;75
15;Chapter 4 Writing Scripts in AppleScript Editor;76
15.1;Working with Script Windows;76
15.1.1;Compiling a Script;77
15.1.2;Running and Stopping a Script;78
15.1.3;Recording a Script;78
15.1.4;Viewing the Result of Running a Script;79
15.1.5;Viewing the Events Sent by a Running Script;79
15.1.6;Adding a Description to a Script;80
15.2;Viewing Application Dictionaries;80
15.3;Other Useful AppleScript Editor Features;81
15.3.1;Using the Library Window;82
15.3.2;Navigating to a Handler in a Script;83
15.3.3;Viewing the Event Log History;84
15.3.4;Scripting the AppleScript Editor;84
15.3.5;Using Context Menu Scripts;85
15.3.6;Viewing the Bundle Contents Drawer;85
15.3.7;Setting the Script Formatting Preferences;86
15.4;Saving Scripts;88
15.4.1;Text-Based Scripts;89
15.4.2;Compiled Scripts;89
15.4.2.1;Saving Scripts As Run Only;90
15.4.2.2;Saving Scripts As Bundles;91
15.4.3;Script-Based Applications (Applets);92
15.4.3.1;Droplets;93
15.4.3.2;Stay-Open Applets;94
15.4.3.3;Saving Applets As Run Only;94
15.4.3.4;Customizing the Startup Screen;94
15.5;Other Tools for Writing and Running AppleScripts;95
15.5.1;The System-wide Script Menu;95
15.5.1.1;Where Are the Menu Scripts Stored?;96
15.5.1.2;Adding Your Own Scripts;97
15.5.2;Third-Party AppleScript Editors;97
15.5.2.1;Smile;97
15.5.2.2;Script Debugger;98
15.5.3;Developing GUI Applications;99
15.5.4;Command-Line Tools;99
15.6;Summary;99
16;Chapter 5 Understanding How Application Scripting Works;100
16.1;A Quick Application Scripting Example;101
16.2;Understanding Objects;102
16.2.1;How Objects Are Categorized by Class;102
16.2.2;Introducing Object Properties;104
16.2.3;Introducing Object Elements;107
16.3;Understanding Commands;109
16.3.1;Introducing Command Names;110
16.3.2;Introducing Command Parameters;110
16.3.3;Commands Must Be Targeted at Objects;112
16.3.4;Commands Can Return Results or Report Errors;113
16.4;Understanding the Application Object Model;114
16.4.1;How Objects Can Contain Other Objects;115
16.4.2;How AppleScript Refers to Application Objects;116
16.4.3;Exploring a Typical Object Model;121
16.5;Understanding Application Dictionaries;126
16.5.1;Introducing AppleScript Editor’s Dictionary Viewer;127
16.5.2;How Classes Are Documented;130
16.5.2.1;Viewing the Properties and Elements Defined by a Class;131
16.5.2.2;How Inheritance Describes Features Shared Between Classes;132
16.5.2.3;Class Definitions Can Be Spread Across More than One Suite!;137
16.5.2.4;Browsing the Containment Hierarchy;138
16.5.2.5;How Commands Are Documented;141
16.5.2.6;Application Dictionaries Don’t Tell You Everything!;143
16.6;More on application Objects;146
16.6.1;Creating application Objects;146
16.6.1.1;Identifying Applications by Name;147
16.6.1.2;Identifying Applications by Path;147
16.6.1.3;Identifying Applications by Bundle ID;147
16.6.1.4;Identifying Applications by Remote URL;148
16.6.2;The Standard Properties of application Objects;149
16.6.3;How AppleScript Compiles tell application ... Blocks;150
16.7;More on Constructing References;151
16.7.1;Referring to Properties;152
16.7.2;Referring to Elements;152
16.7.2.1;Identifying All Elements;153
16.7.2.2;Identifying an Element by Its Index, or Position;153
16.7.2.3;Identifying an Element by Its Name;155
16.7.2.4;Identifying an Element by Its Unique ID;156
16.7.2.5;Identifying an Element Before or After Another Element;157
16.7.2.6;Identifying a Range of Elements;158
16.7.2.7;Identifying Elements Using the whose Clause;159
16.7.2.8;Referring to Insertion Locations;161
16.8;Summary;162
17;Chapter 6 Learning to Work with AppleScript Objects;165
17.1;How AppleScript Represents Information As Objects;166
17.1.1;What Kinds of Objects Does AppleScript Provide?;166
17.1.2;Creating New Objects;167
17.1.3;Getting Information from Objects;167
17.2;How AppleScript Works with Objects;168
17.2.1;Manipulating Objects with Commands;168
17.2.1.1;Introducing the Five Built-in Commands;168
17.2.1.2;Introducing Scripting Addition Commands;169
17.2.1.3;Introducing User-Defined Commands;170
17.2.2;Manipulating Objects with Operators;170
17.2.2.1;What Makes Operators Special?;171
17.2.2.2;What Kinds of Operators Does AppleScript Provide?;172
17.2.2.2.1;The Concatenation Operator;172
17.2.2.2.2;Math Operators;172
17.2.2.2.3;Comparison Operators;173
17.2.2.2.4;Containment Operators;173
17.2.2.2.5;Boolean Operators;174
17.2.2.2.6;The Coercion Operator;174
17.2.2.2.7;The a reference to Operator;175
17.2.3;Coercing Objects;175
17.2.4;Storing Objects in Variables;176
17.2.4.1;How Are Identifiers Written?;177
17.2.4.2;Where Can Variables Be Used?;178
17.3;Working with Boolean Objects;179
17.3.1;Boolean Operators;180
17.3.1.1;The not Operator;180
17.3.1.2;The and Operator;181
17.3.1.3;The or Operator;181
17.3.1.4;How Boolean Operators Are Evaluated;182
17.3.2;Boolean-Related Coercions;182
17.4;Summary;183
18;Chapter 7 Working with Text;184
18.1;Introducing Text;184
18.1.1;A Brief History of Text;185
18.1.1.1;When Is Text Not Text?;185
18.1.1.2;Understanding Character Sets;186
18.1.1.3;The Problem with Character Sets;187
18.1.1.4;Unicode to the Rescue!;190
18.1.2;Introducing Text in AppleScript 2.0;190
18.2;How to Write Literal Strings in AppleScript;191
18.3;The Properties of Text;195
18.3.1;The class Property;195
18.3.2;The length Property;195
18.3.3;The quoted form Property;195
18.3.4;The id Property;195
18.4;The Elements of Text;196
18.4.1;Characters;196
18.4.2;Words;199
18.4.3;Paragraphs;200
18.4.4;Text Ranges;200
18.5;Operators and Commands;202
18.5.1;Joining Strings;202
18.5.2;Comparing Strings;203
18.5.3;Checking for Strings Within Strings;205
18.5.4;Considering and Ignoring Attributes;206
18.5.5;The count Command;210
18.5.6;The offset Command;210
18.5.7;Coercing to and from Text;211
18.6;Working with Text Item Delimiters;213
18.6.1;Splitting Strings with Text Item Delimiters;213
18.6.2;Combining List Items into a Single String;215
18.6.3;Finding and Replacing Text;217
18.7;How AppleScript Text Works in Tiger;218
18.7.1;The Many Different Classes of Text;219
18.7.2;Working with the Various Text Classes;219
18.7.3;The ASCII number and ASCII character Commands;221
18.8;Example Projects;222
18.8.1;Defining a Find-and-Replace Command;223
18.8.2;Transferring Meeting Arrangements from Mail to iCal;225
18.8.2.1;Getting the Message from Mail;226
18.8.2.2;Parsing the Message Text;229
18.8.2.3;Creating the Event in iCal;232
18.9;Summary;234
19;Chapter 8 Working with Numbers;236
19.1;Introducing Integers and Reals;236
19.2;Operators and Commands;237
19.2.1;Math Operations;238
19.2.1.1;Adding, Subtracting, Multiplying, and Dividing Numbers;238
19.2.1.2;Negating Numbers;240
19.2.1.3;Calculating the Integral and Remainder;240
19.2.1.4;Using the Exponent Operator;241
19.2.2;Comparison Operations;242
19.2.2.1;Comparing Reals Can Be Trickier Than You Think;243
19.2.2.2;Performing Multiple Comparisons;244
19.2.3;Introducing Operator Precedence;245
19.2.4;The round Command;246
19.2.4.1;Rounding Up;247
19.2.4.2;Rounding Down;247
19.2.4.3;Rounding Toward Zero;247
19.2.4.4;Rounding to Nearest;248
19.2.4.5;Rounding As Taught in School;248
19.2.5;The random number Command;248
19.2.5.1;Random Number Result;249
19.2.5.2;Parameters;249
19.2.6;Coercing to and from Numbers;250
19.3;Example Projects;252
19.3.1;Defining a Round-to-Decimal-Places Command;252
19.3.2;Blackjack!;254
19.3.3;Kitchen Timer;258
19.4;Summary;261
20;Chapter 9 Working with Dates;262
20.1;Introducing Dates;262
20.1.1;Understanding Date and Time Formats;263
20.1.2;Forming Dates On-the-Fly;265
20.1.3;Specifying a Time Relative to a Date;267
20.2;The Properties of Dates;268
20.2.1;The class Property;268
20.2.2;The year Property;268
20.2.3;The month Property;268
20.2.4;The day Property;269
20.2.5;The weekday Property;269
20.2.6;The hours Property;270
20.2.7;The minutes Property;270
20.2.8;The seconds Property;270
20.2.9;The time Property;270
20.2.10;The date string Property;271
20.2.11;The short date string Property;271
20.2.12;The time string Property;271
20.2.13;Setting Date Properties;271
20.3;Operators and Commands;273
20.3.1;Comparison Operators;273
20.3.2;Math Operators;275
20.3.2.1;Some Useful Constants;275
20.3.2.2;Calculating Time Differences;276
20.3.3;The current date Command;278
20.3.4;The time to GMT Command;279
20.4;Example Projects;279
20.4.1;Deleting Old Files;280
20.4.1.1;Creating the Script;280
20.4.1.2;Adding the User Interaction Portion;282
20.4.2;Alarm Clock;284
20.5;Summary;287
21;Chapter 10 Working with Lists and Records;288
21.1;Introducing Lists and Records;288
21.1.1;What Is a List?;288
21.1.2;What Is a Record?;289
21.1.3;How Are Lists and Records Used in Scripts?;290
21.2;Working with Lists;290
21.2.1;The Properties of a List;291
21.2.1.1;The class Property;291
21.2.1.2;The length Property;291
21.2.1.3;The rest Property;291
21.2.1.4;The reverse Property;292
21.2.2;The Elements of a List;292
21.2.2.1;Getting Items;292
21.2.2.2;Setting Items;294
21.2.2.3;Adding Items;294
21.2.2.4;“Removing” Items;294
21.2.3;Operators and Commands;295
21.2.3.1;Concatenating Lists;295
21.2.3.2;Comparing Lists;296
21.2.3.3;Checking for Sublists;296
21.2.3.3.1;The starts with Operator;296
21.2.3.3.2;The ends with Operator;297
21.2.3.3.3;The contains Operator;297
21.2.3.3.4;The is in Operator;298
21.2.3.3.5;More Uses for Containment Operators;298
21.2.3.4;Counting Lists;299
21.2.3.5;Coercing to and from Lists;299
21.2.4;Processing List Items with a Repeat Loop;300
21.2.5;Sorting Items in a List;302
21.3;Working with Records;303
21.3.1;Getting and Setting the Properties of a Record;305
21.3.2;Operators and Commands;307
21.3.2.1;Concatenating Records;307
21.3.2.2;Comparing Records;307
21.3.2.3;Checking for Subrecords;307
21.3.2.4;Coercing from Records;307
21.3.2.5;Counting Records;308
21.4;Example Project: Measuring Word Frequency in TextEdit;308
21.4.1;Planning the Script;308
21.4.2;Developing the Script;309
21.4.3;Conclusion;312
21.5;Summary;313
22;Chapter 11 Storing Objects in Variables ;314
22.1;Creating Variables;314
22.1.1;Declaring Your Variables;315
22.1.2;Choosing Your Variable Names;316
22.1.2.1;When Keywords and Identifiers Conflict;316
22.1.2.2;Tips for Avoiding Problems with Variable Names;317
22.1.2.3;Follow Good Naming Practices;318
22.1.2.4;Break All the Rules!;320
22.2;Working with Local Variables;320
22.2.1;Understanding Local Variable Scope;321
22.2.2;Passing Values to and from User-Defined Handlers;324
22.3;Working with Properties and Global Variables;326
22.3.1;Understanding Property and Global Variable Scope;326
22.3.2;How Properties (and Global Variables) Can Retain Values Between Runs;327
22.3.3;When to Use Properties and Global Variables;328
22.3.3.1;Managing User Preferences;328
22.3.3.2;Enabling Debugging Code;330
22.3.3.3;Clarifying the Meaning of Important Hard-Coded Values;330
22.3.3.4;Importing Script Libraries;331
22.4;Using AppleScript’s Built-in Variables;331
22.4.1;Variables Containing Predefined Values;332
22.4.1.1;The return, linefeed, space, tab, and quote Variables;332
22.4.1.2;The weeks, days, hours, and minutes Variables;333
22.4.1.3;The pi Variable;334
22.4.2;Variables Containing Objects of Special Interest;334
22.4.2.1;The it Variable;334
22.4.2.2;The me Variable;335
22.4.2.3;The result Variable;338
22.5;Summary;339
23;Chapter 12 More on Commands;340
23.1;Understanding How and Where Commands Are Defined;340
23.1.1;Application-Defined Commands;340
23.1.2;Scripting Addition Commands;343
23.1.3;AppleScript Commands;344
23.1.4;User-Defined Commands;345
23.2;Picking the Right Target for Your Commands;346
23.3;The Five Standard AppleScript Commands;348
23.3.1;The get Command;348
23.3.2;The set Command;348
23.3.3;The copy Command;349
23.3.4;The count Command;351
23.3.5;The run Command;351
23.4;Commands That All Applications Understand;352
23.4.1;The run Command;352
23.4.2;The launch Command;353
23.4.3;The open Command;353
23.4.4;The activate Command;354
23.4.5;The quit Command;354
23.5;The Standard Suite of Application Commands;355
23.5.1;The get Command;355
23.5.2;The set Command;356
23.5.3;The make Command;357
23.5.4;The exists Command;359
23.5.5;The count Command;359
23.5.6;The move Command;360
23.5.7;The duplicate Command;361
23.5.8;The delete Command;362
23.5.9;The print Command;363
23.5.10;The save Command;364
23.5.11;The close Command;365
23.6;More on Working with get, set, and copy Commands;366
23.6.1;When Do Implicit get Commands Occur?;366
23.6.2;When Are Explicit get Commands Necessary?;368
23.6.3;Telling the Difference Between AppleScript and Application set Commands;371
23.6.4;Getting and Setting Multiple Values in a Single Statement;372
23.6.5;Using copy As an Application Command;373
23.7;Changing How Commands Are Handled;375
23.7.1;Considering and Ignoring Application Responses;375
23.7.2;Considering and Ignoring Other Attributes;378
23.7.3;Controlling the Timeout Delay for Long-Running Commands;378
23.8;Sending Commands to Remote Applications;380
23.8.1;Enabling Remote Apple Events;380
23.8.2;Talking to Remote Machines;382
23.8.3;Authenticating Access to Remote Machines;383
23.8.4;Compiling Scripts Offline;384
23.8.5;Using the choose remote application Command;385
23.8.6;Targeting Remote Applications by User and Process IDs;385
23.8.7;Launching Remote Applications;387
23.9;Summary;387
24;Chapter 13 More on Operators and Coercions;389
24.1;Understanding the a reference to Operator;389
24.2;Introducing Unit Type Conversions;393
24.3;A Summary of AppleScript Coercions;394
24.3.1;Coercing Class and Constant Names;395
24.3.2;Coercing Numbers and Text;396
24.3.3;Coercing File Objects;397
24.3.4;Coercing Lists;398
24.4;A Summary of AppleScript Operators;399
24.4.1;Boolean Logic Operators;399
24.4.2;The Concatenation Operator;399
24.4.3;Math Operators;400
24.4.4;Comparison Operators;401
24.4.5;Containment Operators;402
24.4.6;The Coercion Operator;403
24.4.7;The a reference to Operator;403
24.5;Operator Precedence in Detail;404
24.5.1;Understanding Precedence;405
24.5.2;Understanding Forms of Association;406
24.5.3;Understanding when You Should Use Parentheses;407
24.6;Summary;408
25;Chapter 14 Making Decisions Using Conditionals and Loops;409
25.1;Choosing Your Course with Conditional Blocks;409
25.1.1;Understanding the Basic Conditional Statement;410
25.1.2;The Different Flavors of Conditional Statements;411
25.1.3;Offering an Alternative Ending with the else Clause;411
25.1.4;Offering Multiple Choices with else if Clauses;412
25.1.5;Tips for Writing Conditional Statements;413
25.1.5.1;Using a Condition in a Single Line;413
25.1.5.2;Avoiding Unneeded Conditional Statements;413
25.1.5.3;Is It True?;413
25.1.5.4;Testing a Value Against Multiple Options;414
25.2;Running an Assembly Line with Repeat Loops;414
25.2.1;The Different Flavors of Repeat Loops;415
25.2.2;Repeating Forever;416
25.2.3;Repeating n Times;417
25.2.4;Repeating with Numbers in a Range;417
25.2.5;Repeating with Items in a List;420
25.2.6;Repeating While/Until a Condition Is Met;424
25.2.7;Tips for Writing Repeat Statements;426
25.2.7.1;Using Loops to Avoid Repetition;426
25.2.7.2;Naming Loop Variables;428
25.2.7.3;Choosing the Right Loop for the Job;428
25.2.7.4;Avoid Looping when Possible;429
25.3;Summary;430
26;Chapter 15 Making Decisions When Dealing with Errors;432
26.1;Understanding Compilation Errors;433
26.1.1;Simple Typos;433
26.1.2;Unbalanced Statements;433
26.1.3;Unbalanced Parentheses and Unescaped Quotes;433
26.1.4;Unrecognized Keywords;434
26.1.5;Reserved Word Mishaps;434
26.1.6;Invalid Date Literals;435
26.2;Understanding Runtime Errors;435
26.2.1;How Runtime Errors Work in AppleScript;435
26.2.2;Understanding the Psychology of an Error;438
26.2.3;Understanding the Anatomy of an Error;438
26.2.4;Trapping Runtime Errors;439
26.2.4.1;Using the try Block;439
26.2.4.2;Using the Full try Statement;440
26.2.4.3;Knowing What to Do in Case of an Error;440
26.2.4.4;Putting Error Numbers to Use;443
26.2.4.4.1;Testing For Multiple Error Numbers;443
26.2.4.4.2;Nesting try Handlers;444
26.2.5;Generating Runtime Errors;444
26.2.6;Tips for Handling Runtime Errors;447
26.2.6.1;Being Careful Not to Trap Too Much;447
26.2.6.2;Providing More Detailed Error Messages;447
26.2.6.3;Using a Scriptwide try Statement;448
26.2.6.4;Logging Errors to a File;449
26.3;Understanding Common Error Numbers;450
26.3.1;Identifying Operating System Errors;450
26.3.2;Identifying Apple Event Errors;451
26.3.3;Identifying Application Scripting Errors;452
26.3.4;Identifying AppleScript Language Errors;453
26.4;Summary;454
27;Chapter 16 Interacting with the User;455
27.1;Creating Basic Dialog Boxes and Gathering Text Input;455
27.1.1;Introducing the display dialog Command;455
27.1.1.1;From the Dictionary: display dialog;455
27.1.1.2;From the Dictionary: dialog reply;456
27.1.1.3;Using the Basic Form of the Command;456
27.1.1.4;Dealing with the Erroneous Cancel Button;457
27.1.1.5;Creating Custom Buttons;458
27.1.1.6;Specifying a Default Button;458
27.1.1.7;Specifying a Cancel Button;459
27.1.1.8;Adding a Title;460
27.1.1.9;Showing Icons in Dialog Boxes;460
27.1.1.10;Using an Icon File in a Dialog Box;461
27.1.1.11;Getting Text Input from the User;462
27.1.1.12;Creating Password Dialog Boxes;463
27.1.1.13;Dismissing Dialogs Automatically;463
27.1.1.14;Validating User-Entered Text;464
27.1.2;Introducing the display alert Command;465
27.1.2.1;From the Dictionary: display alert;465
27.1.2.2;Using the Basic Form of the Command;466
27.1.2.3;Using the message Parameter;466
27.1.2.4;Using the as Parameter;467
27.1.2.5;Setting the Button Behavior;467
27.1.3;Introducing the choose from list Command;467
27.1.3.1;From the Dictionary: choose from list;468
27.1.3.2;Getting the Results of the Command;468
27.1.3.3;Using the Basic Command;468
27.1.3.4;Creating a Custom Prompt;469
27.1.3.5;Adding a Title;470
27.1.3.6;Setting the Default Selection;470
27.1.3.7;Restricting the Selection;471
27.1.3.8;Customizing Buttons;472
27.2;Choosing Files, Folders, and Disks;472
27.2.1;Introducing the choose file Command;472
27.2.1.1;From the Dictionary: choose file;473
27.2.1.2;Getting the Results of the Command;473
27.2.1.3;Figuring Out When to Use the Command;473
27.2.1.4;Using the Basic Command;474
27.2.1.5;Creating a Custom Prompt;474
27.2.1.6;Restricting to Specific File Types;475
27.2.1.7;Setting the Default Location;476
27.2.1.8;Picking Invisibles;476
27.2.1.9;Allowing Multiple Selections;477
27.2.1.10;Showing Package Contents;477
27.2.2;Introducing the choose file name Command;478
27.2.2.1;From the Dictionary: choose file name;478
27.2.2.2;choose file name vs. choose file;478
27.2.2.3;Figuring Out When to Use the Command;478
27.2.2.4;Getting the Results of the Command;478
27.2.2.5;Using the Basic Command;479
27.2.2.6;Creating a Custom Prompt;479
27.2.2.7;Setting a Default Name and Location;479
27.2.2.8;Replacing an Existing File;480
27.2.2.9;Seeing an Example in Action;480
27.2.3;Introducing the choose folder Command;481
27.2.3.1;From the Dictionary: choose folder;481
27.2.3.2;Using the Command;481
27.2.3.3;Figuring Out When to Use the Command;482
27.2.3.4;Setting the Parameters;482
27.2.3.5;Choosing a Folder Once;482
27.3;Choosing Other Types of Items;483
27.3.1;Introducing the choose application Command;483
27.3.1.1;From the Dictionary: choose application;483
27.3.1.2;Using the Command;484
27.3.2;Introducing the choose remote application Command;484
27.3.2.1;From the Dictionary: choose remote application;485
27.3.2.2;Using the Command;485
27.3.3;Introducing the choose URL Command;485
27.3.3.1;From the Dictionary: choose URL;485
27.3.3.2;Using the Command;486
27.3.4;Introducing the choose color Command;486
27.3.4.1;From the Dictionary: choose color;487
27.3.4.2;Getting the Results of the Command;487
27.3.4.3;Figuring Out When to Use the Command;487
27.3.4.4;Using the Basic Command and Using It with Parameters;487
27.4;Summary;488
28;Chapter 17 Working with Files;489
28.1;Identifying Files, Folders, and Disks;489
28.1.1;Using Path Strings;490
28.1.1.1;Let’s start with an example of an HFS path: Understanding HFS Paths;490
28.1.1.2;Understanding POSIX Paths;491
28.1.2;Using File System Objects;492
28.1.2.1;Understanding Alias Objects;492
28.1.2.1.1;How Aliases Work;493
28.1.2.1.2;Using Aliases to Keep Track of File System Items;494
28.1.2.1.3;Converting to and from Alias Objects;495
28.1.2.2;Understanding File “Objects”;496
28.1.2.2.1;How Files (Really) Work;496
28.1.2.2.2;Converting to and from File References;498
28.1.2.3;Understanding POSIX File Objects;498
28.1.2.3.1;How POSIX Files Work;498
28.1.2.3.2;Converting to and from POSIX File Objects;499
28.1.3;File URL Strings;500
28.2;Reading and Writing Files;501
28.2.1;Commands for Reading and Writing Files;501
28.2.1.1;Reading Files;501
28.2.1.1.1;From the Dictionary;501
28.2.1.1.2;Using the read Command;502
28.2.1.2;Opening and Closing Access to Files;502
28.2.1.2.1;From the Dictionary;502
28.2.1.2.2;Opening a File for Reading or Writing;502
28.2.1.2.3;The open for access Result;503
28.2.1.3;Read Command Parameters;503
28.2.1.3.1;Reading Different Kinds of Data;503
28.2.1.3.2;Using a Delimiter to Read Text into a List;504
28.2.1.3.3;Reading a Specific Number of Bytes;505
28.2.1.3.4;The from and to Parameters;505
28.2.1.3.5;The before and until Parameters;506
28.2.1.3.6;Using the open for access and read Commands Together;506
28.2.1.4;Working with the End-of-File (EOF) Commands;507
28.2.1.4.1;From the Dictionary;508
28.2.1.4.2;Getting a File’s EOF;508
28.2.1.4.3;Setting a File’s EOF;508
28.2.1.5;Writing Files;509
28.2.1.5.1;From the Dictionary;509
28.2.1.5.2;Using the write Command;509
28.2.1.5.3;How Much to Write and Where to Start;510
28.2.1.5.4;Useful File Writing Handlers;511
28.2.1.5.5;Using the write Command to Create a Script Log;511
28.2.1.5.6;Saving and Loading AppleScript Lists and Records;513
28.2.2;Dealing with Text File Encodings;513
28.2.2.1;About ASCII, MacRoman, and Unicode Character Sets;513
28.2.2.2;Reading and Writing Text Files in Different Encodings;514
28.2.2.2.1;Reading and Writing UTF-8 Encoded Files;515
28.2.2.2.2;Reading and Writing UTF-16 Encoded Files;515
28.2.2.2.3;Reading and Writing Files in Other Encodings;517
28.2.2.3;What Happens if the Wrong Encoding is Used?;518
28.2.2.4;A Summary of Common Text File Encodings;520
28.2.2.5;Further Reading on Text Encodings;520
28.3;Summary;520
29;Chapter 18 Organizing Your Code with Handlers;522
29.1;What Are User-Defined Handlers?;522
29.2;Creating a Simple Handler;524
29.3;Using Parameters;525
29.4;What’s the Result?;526
29.4.1;Using the return Statement;526
29.4.2;Working with Return Values;527
29.4.3;Can a Handler Return More Than One Result?;528
29.5;Specifying Handler Parameters;529
29.5.1;Using Positional Parameters;530
29.5.1.1;Definition for Positional Parameter Handlers;530
29.5.1.2;Defining and Calling Positional Parameter Handlers;530
29.5.1.3;Adding Parameters;531
29.5.2;Using Labeled Parameters;532
29.5.2.1;Definition for Positional Parameter Handlers;532
29.5.2.2;Using Predefined Parameter Labels;532
29.5.2.3;Making Up Your Own Labels;534
29.5.2.4;Calling Handlers with Boolean Parameters;534
29.6;Introducing Recursion;536
29.7;Using the run Handler in Scripts;537
29.7.1;I’ve Never Seen No run Handler!;537
29.7.2;When Should You Make the run Handler Explicit?;538
29.8;Working with Handlers in Applets;539
29.8.1;Using the Standard Event Handlers;539
29.8.1.1;The run Event Handler;540
29.8.1.2;The open Event Handler;541
29.8.1.3;The reopen Event Handler;541
29.8.1.4;The quit Event Handler;541
29.8.1.5;The idle Event Handler;542
29.8.2;Using User-Defined Handlers from Other Scripts;543
29.9;Tips for Designing and Using Handlers;543
29.9.1;Organizing Code;543
29.9.2;Reusing Code;544
29.9.3;Thinking Ahead;544
29.9.4;Thinking Small;544
29.9.5;Reorganizing Existing Code;545
29.10;Example Project: A Reusable Associative List;546
29.10.1;Designing the Associative List;547
29.10.2;Writing the Essential Handlers;548
29.10.3;Writing the Extra Handlers;551
29.10.4;Revising the Design;552
29.10.5;Conclusion;554
29.11;Summary;555
30;Chapter 19 Organizing Your Code with Script Objects;557
30.1;Introducing Script Objects;557
30.1.1;What Is a Script Library?;558
30.1.2;What Is Object-Oriented Programming?;559
30.2;Understanding Script Objects;559
30.2.1;Defining a Script Object in a Script;560
30.2.2;Loading and Storing Script Objects from Disk;561
30.2.3;How Variable Scope Works in Script Objects;562
30.3;Working with Script Libraries;564
30.3.1;What Advantages Do Script Libraries Provide?;565
30.3.2;Creating Your First Script Library;566
30.3.3;Where Should You Save Your Library?;566
30.3.4;What Are the Options for Loading Script Libraries?;568
30.3.4.1;Using the load script Command;568
30.3.4.2;Using AppleMods Loader;569
30.4;Beginning Object-Oriented Programming;572
30.4.1;Your First Object: A Better Associative List;573
30.4.1.1;Planning the Conversion;574
30.4.1.2;Converting the make_associative_list Handler;575
30.4.1.3;Repackaging the Remaining Handlers;576
30.4.1.4;Using the Object-Oriented Associative List;578
30.4.2;Extending Objects Through Inheritance;579
30.4.2.1;A Quick Reminder of General Inheritance Concepts;579
30.4.2.2;How Inheritance Works with Script Objects;581
30.4.2.3;Implementing Case-Insensitive and Case-Sensitive Associative Lists;585
30.4.2.4;Testing the New Associative List Objects;587
30.4.3;Creating Plug-and-Play Objects;589
30.4.3.1;Planning the Logging System;591
30.4.3.2;Designing the LogBase Object;591
30.4.3.3;Defining the Concrete Log Objects;594
30.4.3.4;Testing the Finished Logging System;597
30.4.3.5;Conclusion;599
30.5;Summary;599
31;Part III Putting AppleScript to Work;601
32;Chapter 20 Scripting the File System;602
32.1;How the Finder Represents the Mac OS X File System;602
32.1.1;Understanding Containers;604
32.1.2;Understanding Files;607
32.1.3;Understanding Packages;609
32.1.4;Understanding the computer-object Class;609
32.2;How System Events Represents the Mac OS X File System;610
32.2.1;Understanding Files;612
32.2.2;Understanding Folders;613
32.2.3;Understanding Disks;614
32.2.4;Understanding System Events’ alias Class;614
32.2.5;Other Classes of Interest;615
32.2.5.1;The user Class;615
32.2.5.2;The domain Class;615
32.2.5.3;The login item Class;617
32.3;Working with Finder Items;617
32.3.1;Opening and Closing Items;617
32.3.2;Duplicating Files and Folders;618
32.3.3;Deleting Files and Folders;619
32.3.4;Moving Files and Folders;620
32.3.5;Checking if Items Exist;621
32.3.6;Making New Items;621
32.3.7;Sorting Lists of Finder References;622
32.3.8;Ejecting Disks;623
32.3.9;Selecting Items in a Finder Window;623
32.3.10;Converting Finder References to AppleScript Aliases;623
32.4;More on Working with Folders;625
32.4.1;Filtering the Content of Folders;625
32.4.2;Getting the Entire Contents of a Folder;626
32.5;Locating Important Files and Folders with Standard Additions;627
32.5.1;Avoiding Hardcoded Paths to the Startup Disk and Home Folder;628
32.5.2;Getting the Path to the Currently Running Script;629
32.5.3;Getting Paths to Resources in an Application Bundle;631
32.6;Mounting Volumes;633
32.7;Summary;636
33;Chapter 21 Scripting Apple Applications;637
33.1;Scripting iTunes;637
33.1.1;Understanding the iTunes Object Model;638
33.1.2;Working with Sources;640
33.1.3;Working with Tracks and Playlists;641
33.1.4;Example Project: My Themed Playlist;645
33.1.4.1;Gathering the User Input;645
33.1.4.2;Preparing the Playlist;647
33.1.4.3;Adding the Tracks to the Playlist;648
33.2;Scripting Mail;649
33.2.1;Working with Mailboxes;650
33.2.2;Working with Messages;650
33.2.3;Creating Outgoing Messages;655
33.2.4;Working with Mail Rules;656
33.2.5;Example Project: Building a Monthly Message Archive;660
33.2.5.1;Preparing to Write the Script;660
33.2.5.2;Creating the Sub-Mailboxes;662
33.2.5.3;Putting It All Together;663
33.3;Scripting iCal;664
33.3.1;Working with Calendars;666
33.3.2;Working with Events;667
33.4;Scripting Address Book;669
33.4.1;Working with People;670
33.4.2;Working with Groups;673
33.4.3;Working with Rollovers;675
33.4.4;Example Project: Looking Up Contact Information by Name;677
33.5;Scripting Automator;680
33.5.1;Using the Run AppleScript Action;680
33.5.1.1;Understanding the Action’s Input and Output;681
33.5.1.2;Understanding the Action’s Parameters;683
33.5.1.3;Filtering Files with Run AppleScript;684
33.5.2;Scripting the Automator Application;685
33.6;Summary;687
34;Chapter 22 Extending AppleScript with Scripting Additions;689
34.1;Introducing Scripting Additions and Scriptable Faceless Background Applications;689
34.2;Scripting Additions in Detail;691
34.2.1;Scripting Additions and the AppleScript Language;691
34.2.2;Installing Scripting Additions;692
34.2.3;Missing Additions and Garbled Scripts;693
34.2.4;Distributing Scripting Additions with Your Scripts;694
34.2.4.1;Embedding Scripting Additions Within a Script Application;695
34.2.4.2;Using the Mac OS X Installer to Install Your Script and Scripting Additions;697
34.2.5;Understanding Scripting Addition Compatibility Issues;697
34.2.5.1;Caution: Mac OS 9 Scripting Additions Don’t Work on Mac OS X;698
34.2.5.2;Using PowerPC-Only Scripting Additions on Intel-Based Macs;698
34.2.5.3;Using 32-Bit-Only Scripting Additions on 64-Bit Macs;700
34.2.5.4;Working Around Scripting Addition Limitations;700
34.3;Understanding Scriptable Faceless Background Applications;702
34.3.1;Installing Scriptable FBAs;702
34.3.2;Distributing Scriptable FBAs with Your Scripts;702
34.4;Examples of AppleScript Extensions;703
34.4.1;Built-in Extensions;703
34.4.2;Third-Party Extensions;703
34.5;Using the Standard Additions Scripting Addition;704
34.5.1;Providing Audio Feedback;705
34.5.1.1;The beep Command;705
34.5.1.2;The say Command;705
34.5.2;Pausing Your Scripts;706
34.5.2.1;The delay Command;706
34.5.3;Getting and Setting the System Volume;706
34.5.3.1;The get volume settings Command;706
34.5.3.2;The set volume Command;706
34.5.4;Getting System Information;707
34.5.4.1;The system attribute Command;707
34.5.4.2;The system info Command;708
34.5.5;Working with URLs;708
34.5.5.1;The open location Command;709
34.5.5.2;Coercing URLs;709
34.6;Using the Image Events Faceless Background Application;709
34.7;Processing Text with the Satimage ScriptingAddition;711
34.7.1;Downloading and Installing the Satimage Scripting Addition;712
34.7.2;Performing Simple Find and Replace Tasks;712
34.7.3;Counting Occurrences of a Substring in a String;713
34.7.4;Finding and Replacing Substrings in a File;714
34.7.5;Searching and Replacing Across Many Files;715
34.7.6;Finding and Replacing Text with Regular Expressions;715
34.7.6.1;A Brief Background on Regular Expressions;715
34.7.6.2;Using Satimage Regular Expression Commands;719
34.7.7;Batch-Changing File Names;721
34.8;Summary;724
35;Chapter 23 AppleScript Amenities;725
35.1;Using the Services Menu;725
35.1.1;AppleScript Editor Services;726
35.1.2;Creating Your Own Services;726
35.2;Scheduling Scripts with iCal;729
35.3;Triggering Scripts with Folder Actions;730
35.3.1;Defining Event Handlers for Folder Actions;731
35.3.2;Where Are Folder Action Scripts Stored?;731
35.3.3;Managing Your Folder Actions;731
35.3.3.1;Using the Folder Actions Setup Utility;732
35.3.3.2;Using Scripts;732
35.3.4;Creating Your First Folder Action;733
35.3.4.1;Create Your Folder Action Script;733
35.3.4.2;Save Your Script;734
35.3.4.3;Create Your Hot Folder;734
35.3.4.4;Activate the Folder Actions Setup Utility;734
35.3.4.5;Attach the Folder Action Script to the Folder;734
35.3.4.6;Test Your Folder Action;736
35.4;Controlling Applications with GUI Scripting;736
35.4.1;Enabling GUI Scripting;737
35.4.2;The GUI Scripting Dictionary;737
35.4.3;GUI Scripting Object Structure;737
35.4.4;Basic GUI Scripting Examples;739
35.4.5;Using GUI Scripting Commands;740
35.4.5.1;The click Command;740
35.4.5.2;The keystroke Command;740
35.4.5.3;The key code Command;741
35.4.5.4;Example Project: Searching in Preview;742
35.4.5.5;Introducing PreFab UI Browser;742
35.4.5.6;Beginning the Script;743
35.4.5.7;Performing the Search;744
35.4.5.8;Getting Data from the Search Table;747
35.4.5.9;Understanding the Limitations of GUI Scripting;749
35.5;Working with the Clipboard;750
35.5.1;Getting Clipboard Data into AppleScript;750
35.5.1.1;Understanding How the Mac Clipboard Works;750
35.5.1.2;Finding Out What’s on the Clipboard;751
35.5.1.3;Getting Specific Types of Data from the Clipboard;751
35.5.2;Setting the Clipboard Data;751
35.5.2.1;Using the cut, copy, and paste Commands in Applications;752
35.5.2.2;Using the set the clipboard to Command;753
35.5.2.3;Using GUI Scripting;753
35.5.3;Example Project: Creating PDF Cuttings from Selections in Preview;753
35.6;Summary;756
36;Chapter 24 Scripting iWork and Office;757
36.1;Scripting iWork;757
36.1.1;Scripting Pages;758
36.1.1.1;Creating a New Document;758
36.1.1.2;Working with a Document’s Paragraphs;759
36.1.1.3;Adding Headers and Footers to a Document;761
36.1.1.4;Drawing Shapes in Pages;762
36.1.1.5;Adding Tables and Charts;763
36.1.1.6;Tips for Scripting Pages;764
36.1.2;Scripting Keynote;765
36.1.2.1;Creating a Slideshow;765
36.1.2.2;Choosing a Theme;766
36.1.2.3;Filling Slides with Content;767
36.1.2.4;Working with Transitions;769
36.1.2.5;Scripting an Advanced Screen Reader;771
36.1.3;Scripting Numbers;772
36.1.3.1;Creating Sheets and Tables;773
36.1.3.2;Working with Cells;773
36.2;Scripting Microsoft Office;774
36.2.1;Working with Microsoft Entourage;775
36.2.1.1;Disable the Security Warning;776
36.2.1.2;Creating Messages;777
36.2.1.3;Some Shortcuts;779
36.2.1.4;Working with Contacts;780
36.2.1.4.1;Creating Contacts;781
36.2.1.4.2;Selecting and Changing Multiple Contacts;782
36.2.1.4.3;Setting Categories;783
36.2.1.4.4;Creating Calendar Events;784
36.2.1.4.5;Extracting Information from a Whole Lot of Messages in a Folder;787
36.2.2;Working with Excel;791
36.2.2.1;Creating Workbooks and Worksheets;792
36.2.2.2;Working with Ranges;793
36.2.2.3;Creating Charts;800
36.2.3;Working with Word;802
36.2.3.1;Creating a Word Document;802
36.2.3.2;Working with Selected Text;803
36.2.4;Where Next?;805
36.3;Summary;806
37;Chapter 25 Scripting Data and Databases;807
37.1;Automating FileMaker Pro with AppleScript;808
37.1.1;The FileMaker Object Model and the Commands You Can Use;809
37.1.1.1;The database Class;810
37.1.1.2;The window Class;811
37.1.1.3;The table Class;811
37.1.1.4;The layout Class;812
37.1.1.5;The record, field, and cell Classes;813
37.1.2;Finding Data Quickly with the whose Clause;816
37.1.2.1;Using the whose Clause to Retrieve Relational Data;817
37.1.2.2;Using the find Command;818
37.1.3;Running AppleScripts from Inside FileMaker Pro;820
37.2;Scripting Runtime Labs’ MacSQL;821
37.2.1;Getting Connected;822
37.2.2;Using a Simple select Command;823
37.2.3;More on Result Sets;823
37.2.4;Some Useful Handlers;824
37.3;Database Events;826
37.3.1;Database Events Classes and Commands;826
37.3.2;Database Events Examples;827
37.4;Summary;828
38;Chapter 26 Scripting Adobe InDesign;830
38.1;Learning by Example;831
38.2;Understanding the InDesign Object Model;833
38.2.1;How InDesign Organizes Its Many Properties;833
38.2.2;How InDesign Manages Units of Measurement;836
38.2.3;How to Set Properties Safely when Making New Objects;837
38.3;Working with Documents;838
38.3.1;Working with Document Layers;842
38.3.2;Understanding InDesign References;844
38.4;Working with Text;844
38.4.1;Working with Text Stories;845
38.4.2;Working with References to Text;846
38.5;Working with Graphics;848
38.6;Drawing Lines;849
38.7;Example Project: An InDesign Scripts Launcher;850
38.8;Working with Tables;853
38.8.1;Importing Table Text from a Spreadsheet;854
38.8.2;Copying Formatting Between Cells;856
38.9;Working with Selections;858
38.9.1;Example Project: Captioning a Selected Graphic;859
38.9.2;Example Project: Cleaning Up Selected Text;861
38.10;Labeling Objects for Use in Workflow Scripts;863
38.11;Taking Advantage of AppleScript-Specific Preferences;865
38.12;Example Project: Replacing Tags with Images;867
38.12.1;Preparing InDesign;868
38.12.2;Processing the Tags;869
38.12.3;Preparing the Image Files;870
38.12.4;Placing the Graphics;871
38.12.5;Testing the Script;873
38.13;Using InDesign on a Server;873
38.14;Summary;874
39;Chapter 27 Interacting with the Unix Command Line;875
39.1;Why and When Are Shell Scripts Used in AppleScript?;875
39.2;Understanding Unix Scripting Concepts;876
39.2.1;The Unix Command Line and Mac Desktop Compared;876
39.2.2;How the Unix Command Line Works;877
39.2.2.1;The Shell;878
39.2.2.2;Commands;879
39.2.2.3;Pipes;880
39.2.2.4;Other Redirections;880
39.2.3;Getting Help;881
39.2.3.1;Built-in Help;881
39.2.3.2;Other Sources of Help;882
39.2.4;Things to Watch Out For;882
39.2.4.1;Data in Unix Is “Dumb”;882
39.2.4.2;Unix Doesn’t Know About Different Character Sets;883
39.2.4.3;Unix Understands POSIX File Paths Only;883
39.2.4.4;Watch Where You Use Spaces and Other Special Characters!;883
39.2.4.5;Unix Assumes You Know What You’re Doing;884
39.2.5;Some Useful Unix Commands;884
39.3;Running Shell Scripts from AppleScript;885
39.3.1;Scripting the Terminal Application;885
39.3.1.1;Understanding Terminal’s Object Model;885
39.3.1.2;Using the do script Command;886
39.3.1.3;A Simple do script Example;886
39.3.1.4;Limitations of the do script Command;887
39.3.2;Using the do shell script Command;887
39.3.2.1;From the Dictionary;887
39.3.2.2;Understanding the do shell script Command’s Parameters;888
39.3.2.2.1;The Direct Parameter;888
39.3.2.2.2;The as Parameter;888
39.3.2.2.3;The administrator privileges Parameter;888
39.3.2.2.4;The user name and password Parameters;888
39.3.2.2.5;The altering line endings Parameter;888
39.3.2.3;How do shell script Deals with Unicode;889
39.3.2.4;A Simple do shell script Example;890
39.3.2.5;Limitations of the do shell script Command;890
39.3.2.5.1;No User Interaction;890
39.3.2.5.2;Performance Overheads;891
39.3.2.5.3;Can’t Directly Supply Data to Standard Input;891
39.3.3;Assembling Shell Script Strings;891
39.3.3.1;Unix File Paths;891
39.3.3.2;Quoting Arguments;892
39.3.3.3;Absolute Paths, Relative Paths, and the Working Directory;893
39.3.4;Passing Data to Standard Input;895
39.3.4.1;Using echo;895
39.3.4.2;Using Temporary Files;896
39.3.4.2.1;Creating the Temporary File;896
39.3.4.2.2;Writing the Temporary File;897
39.3.4.2.3;Redirecting the Shell Script;897
39.4;Running AppleScript from Shell Scripts;898
39.4.1;Using the osascript Command;898
39.4.2;Passing Parameters to the Script;899
39.4.3;Other Related Commands;900
39.5;Example Projects;900
39.5.1;Simple Text Processing Handlers;900
39.5.1.1;Encoding URLs;901
39.5.1.2;Changing Case;901
39.5.2;Changing File System Permissions;902
39.5.3;Analyzing PDF Files;905
39.6;Summary;908
40;Chapter 28 Using Smile: The AppleScript Integrated Production Environment;909
40.1;Introducing Smile;909
40.1.1;Introducing Smile’s Integrated Engine Architecture;909
40.1.2;About Smile’s Terminal;910
40.1.3;Why Should You Use Smile?;910
40.2;Downloading Smile;911
40.3;Using Smile;911
40.3.1;Using the AppleScript Command-Line Environment;912
40.3.2;Using Smile’s Custom Dialog Boxes;913
40.3.2.1;Creating the Interface;913
40.3.2.2;Programming the Functionality;914
40.3.3;Using Regular Expressions;915
40.3.4;Using the Graphic Engine;916
40.3.5;Using SmileLab;917
40.4;Example Project: Adding Text to a PDF Document;920
40.4.1;Preparing the PDF;920
40.4.2;Rolling Up the Scripts into a Graphical Interface;927
40.4.2.1;Building the Interface;928
40.4.2.2;Programming the Dialog Box;931
40.4.2.3;Handling User Clicks;934
40.4.3;Further Exercises;937
40.5;Summary;938
41;Chapter 29 Tips and Techniques for Improving Your Scripts;939
41.1;Design, in a Nutshell;940
41.1.1;Taking Your Scripting Skills to the Next Level;940
41.1.2;How Much Design Do Your Scripts Need?;941
41.1.3;Starting Out Is Hard (But Gets Easier with Practice);943
41.1.4;How the Design-Driven Approach Changes the Way You Think About Code;945
41.2;Testing and Debugging Your Code;946
41.2.1;General Testing Tips and Techniques;947
41.2.1.1;Design Your Scripts for Easy Testing;947
41.2.1.2;Test Your Code with Bad Data As Well As Good;947
41.2.1.3;Test Your Code As You Go;948
41.2.1.4;Why Testing Matters;949
41.2.2;Debugging in AppleScript Editor;950
41.2.2.1;Viewing Intermediate Results with return and error Statements;950
41.2.2.2;Monitoring a Script’s Progress Using Dialog Boxes;951
41.2.2.3;Using the Event Log;951
41.2.3;Debugging in Script Debugger;953
41.2.3.1;Using the start log and stop log Commands;953
41.2.3.2;Using the Script Window;954
41.2.3.3;Using the Debugging Mode;954
41.2.3.4;Stepping Through Scripts;955
41.2.4;Keeping Track of Changes;956
41.2.4.1;Comparing Scripts with FileMerge;956
41.2.4.2;Managing Your Code with Source Control;959
41.3;Improving the Performance of Your Code;960
41.3.1;The Dos and Don’ts of Optimization;960
41.3.1.1;When Should You Optimize?;961
41.3.1.2;Where Should You Optimize?;961
41.3.1.3;Profiling Your Code with Timing Commands;962
41.3.2;Common AppleScript Optimizations;963
41.3.2.1;Building Up Large Lists;963
41.3.2.2;Building Up Large Strings;964
41.3.2.3;Manipulating Multiple Application Objects with a Single Command;966
41.3.2.4;Filtering Multiple Application Objects with whose Clause References;967
41.3.3;Advanced Optimization Techniques;968
41.3.3.1;Assessing Your Code’s Efficiency with Big O Notation;969
41.3.3.2;Improving the Efficiency of AppleScript Lists;971
41.3.3.3;Linear Search vs. Binary Search;974
41.3.3.4;Bubble Sort vs. Quicksort;976
41.4;Summary;978
42;Chapter 30 Creating Cocoa Applications with AppleScriptObjC;980
42.1;Example Project: HelloAppleScriptObjC;981
42.1.1;Creating the Project in Xcode;982
42.1.2;Adding the AppleScript Code in Xcode;984
42.1.3;Constructing the Interface in Interface Builder;984
42.1.3.1;Understanding Interface Builder’s Interface;984
42.1.3.1.1;The MainMenu Window;985
42.1.3.1.2;The Application Window;985
42.1.3.1.3;The MainMenu.xib – English Window;986
42.1.3.1.4;The Library Palette;986
42.1.3.2;Adding the GUI Objects;987
42.1.3.3;Making Connections;989
42.1.4;Building and Testing the Application;990
42.2;Understanding How Cocoa Works;991
42.2.1;Understanding Outlets;991
42.2.2;Understanding Targets and Actions;991
42.2.3;How AppleScript Interacts with Cocoa Objects;993
42.3;Modifying HelloAppleScriptObjC to Set the Text Field;994
42.3.1;Updating the Code and Testing the Changes;994
42.3.2;What Is All That Code in the Default AppleScript File?;994
42.4;Example Project: PlaySound;996
42.4.1;Creating the Project and Adding the Code;996
42.4.2;Constructing the Interface;997
42.4.3;Building and Testing the Application;998
42.4.4;Understanding How It Works;999
42.5;Viewing the Cocoa Documentation in Xcode;1001
42.5.1;How Cocoa Classes Are Documented;1002
42.5.2;How Cocoa Methods Are Documented;1004
42.5.2.1;The Method Name;1005
42.5.2.2;Parameters;1006
42.5.2.3;Return Value;1006
42.5.2.4;Discussion, Availability, See Also, Related Sample Code, and Declared In;1006
42.6;Example Project: SnapShot;1007
42.6.1;Creating the Project and Starting the Code;1007
42.6.2;Constructing the Interface;1007
42.6.3;Completing the Code;1008
42.6.4;Understanding How It Works;1010
42.6.5;Preparing the Text Fields Using an awakeFromNib Handler;1011
42.6.6;Building and Testing the Application;1012
42.7;Modifying SnapShot to Use Cocoa Bindings;1012
42.7.1;Adjusting the Code for Bindings;1012
42.7.2;Setting Up Bindings in Interface Builder;1013
42.7.3;Building and Testing the Application;1017
42.8;Modifying PlaySound to Use Bundled Sound Files;1017
42.8.1;Adding the Sound File Resources to the Project;1017
42.8.2;Adding the Code;1018
42.8.3;Adding the Pop-Up Button;1018
42.8.4;Building and Testing the Application;1018
42.8.5;Understanding How It Works;1019
42.9;Example Project: KitchenTimer;1020
42.9.1;Creating the Project and Starting the Code;1020
42.9.2;Constructing the Interface;1021
42.9.3;Completing the Code;1024
42.10;Extra Exercises;1026
42.11;Where Next?;1027
42.12;Summary;1028
42.13;Conclusion;1029
43;Index;1030



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.