rent-now

Rent More, Save More! Use code: ECRENTAL

5% off 1 book, 7% off 2 books, 10% off 3+ books

9780764574009

Beginning AppleScript

by
  • ISBN13:

    9780764574009

  • ISBN10:

    0764574000

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2004-12-17
  • Publisher: Wrox
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $40.00 Save up to $0.04
  • Buy New
    $39.96
    Add to Cart Free Shipping Icon Free Shipping

    PRINT ON DEMAND: 2-4 WEEKS. THIS ITEM CANNOT BE CANCELLED OR RETURNED.

Summary

What is this book about?Geared toward programmers with no prior development knowledge, Beginning AppleScript serves as a comprehensive guide to using AppleScript on the Mac OS X platform. This title introduces the reader to AppleScript, and then illustrates how to efficiently start writing scripts through sample programs as each concept is introduced. Exercises at the end of each chapter allow the reader to test and demonstrate their knowledge on how to write functional scripts. The appendices include a list of other resources for additional developer information, and a summary of the language suitable for reference.

Author Biography

Stephen G. Kochan has been developing software and writing books for over 20 years. He is the author and coauthor of several best-selling titles on the C language, including Programming in C and Programming in ANSI C (both from Sams Publishing), Programming C for the Mac (Macmillan Computer Publishing), and Topics in C Programming (Wiley Publishing), as well as several Unix titles, including Exploring the Unix System and Unix Shell Programming (both Sams Publishing), and Unix System Security (Hayden Books). His most recent title on Mac programming is Programming in Objective-C (Sams Publishing), which is a tutorial on the primary programming language used on the Mac for application development.

Table of Contents

About the Author v
Acknowledgments xxv
Introduction 1(1)
Who This Book Is For
1(1)
How This Book Is Structured
2(2)
What You Need to Use This Book
4(1)
Conventions
5(1)
Source Code
5(1)
Errata
5(1)
p2p.wrox.com
6(1)
Writing Your First AppleScript Program
7(18)
Starting with Script Editor
7(2)
Try It Out: Typing Your First Program
8(1)
Compiling and Running Your Program
9(3)
Try It Out: Running Your First Program
9(2)
Try It Out: Saving Your First Program
11(1)
Extending Your First Program
12(3)
Reporting Errors in Your Programs
12(2)
Try It Out: Adding a Description to Your Program
14(1)
An AppleScript Command to Display a Dialog
15(2)
Understanding the Buttons Parameter in the display dialog Command
17(4)
Try It Out: Using the display dialog's Buttons Parameter
17(2)
Changing the Labels on a Button
19(1)
Try It Out: Setting the Default Button In a Dialog
19(1)
Adding an Icon to Your Dialog Box
20(1)
Try It Out: Adding a Note Icon to Your Dialog
21(1)
Multiple AppleScript Commands
21(1)
Try It Out: Add a ``Beep''
21(1)
Adding Comments to Your Programs
22(1)
Summary
23(1)
Exercises
24(1)
Variables, Classes, and Expressions
25(44)
Working with Variables
25(9)
Variable Names and the set Command
25(2)
Accessing the Value of a Variable and the get Command
27(1)
Try It Out: Working with Variables
27(1)
Try It Out: More on Working with Variables
27(2)
Try It Out: Understanding Case In Variable Names
29(3)
Writing Special Variable Names
32(1)
The Special result Variable
33(1)
More on Commands and Statements
34(4)
Commands
34(1)
Statements
34(1)
The log Command and the Event Log
35
Try It Out: Using the Event Log
34(2)
Try It Out: Using the Event Log History
36(2)
Basic Data Type Classes
38(5)
The string Class
38(1)
The Integer Class
39(1)
Small and Double Integer Classes
39(1)
The real Class
39(1)
The Boolean Class
40(1)
Try It Out: Understanding Boolean Values
41(1)
The class Command
42(1)
Try It Out: Using the Class Command
42(1)
Basic Data Type Conversions
43(6)
Coercing a Data Type Using the as Operator
44(1)
Try It Out: Basic Data Type Conversions with the as Operator
44(5)
Arithmetic Operators and Expressions
49(4)
Try It Out: Understanding Arithmetic Operations
49(4)
The Date Class
53(13)
Try It Out: Understanding the Date Format
54(1)
Getting Date Properties
54(1)
Try It Out: Getting the Properties of a Date
54(2)
Setting Date Properties
56(1)
Try It Out: Setting Date Properties
57(3)
Performing Arithmetic with Dates
60(1)
Try It Out: Understanding Arithmetic with Dates
60(2)
Classes of Weights and Measures
62(1)
Try It Out: Using Weights and Measures
63(3)
Summary
66(1)
Exercises
67(2)
Making Decisions
69(32)
The if Statement
69(2)
A Single Line Form of the if Statement
70(1)
AppleScript's Relational Operators
71(9)
Try It Out: Testing the Various Relational Operators
72(1)
Numeric Tests
73(1)
String Tests
74(2)
Date Tests
76(1)
Getting Data from the User
77(2)
Try It Out: Taking the Absolute Value of a Number
79(1)
The if-else Statement
80(2)
Nested if Statements
82(1)
The if-else if Statement
83(3)
Try It Out: Displaying a Message Based on the Day of the Week
84(2)
Compound Relational Tests
86(3)
Try It Out: Testing Whether a Year Is a Leap Year
88(1)
Creating Your First Application
89(5)
Try It Out: Speaking a Salutation
90(2)
Try It Out: Displaying a Startup Screen
92(1)
Try It Out: Have Some Fun: Get Your Salutation at Log In
93(1)
Catching Errors with the try Statement
94(4)
Try It Out: Introducing the try Statement
94(2)
Try It Out: Error Handling with the try Statement
96(1)
Try It Out: More on the try Statement
96(2)
Summary
98(1)
Exercises
98(3)
Program Looping
101(24)
The repeat...times Statement
101(1)
Try It Out: Log a Message Five Times
101(1)
The repeat with Statement
102(9)
Try It Out: Counting from 1 to 10
102(2)
Writing a Loop with an Increment
104(1)
Try It Out: Counting Down from 10
105(1)
Try It Out: A Program to Sum the Integers from 1 to n
106(2)
Your First Look at a Dictionary
108(1)
Try It Out: Looking Up a Command in a Dictionary
109(2)
The repeat while Statement
111(2)
Try It Out: Counting from 1 to 10
111(2)
Using Flags
113(5)
Another Look at the Triangular Number Program
113(1)
Try It Out: Getting Another Chance
113(2)
A Final Look at the Triangular Number Program
115(1)
Try It Out: Limiting the Number of Attempts
115(2)
A Quick Look at the Concatenation Operator
117(1)
The repeat until statement
118(4)
Try It Out: A Simple Guessing Game
119(3)
The repeat with Statement for Lists
122(1)
Try It Out: Sequencing through the Elements in a List
122(1)
Setting Up an Infinite Loop with repeat
123(1)
Summary
123(1)
Exercises
124(1)
Working with Strings
125(36)
Strings, Text, and Unicode Text
125(1)
The Null String
126(1)
Review of Concatenation
126(1)
Getting the Size of a String
127(1)
Using Special String Characters
128(2)
Special Properties Used Outside Strings
128(1)
Escape Characters Used inside Strings
128(1)
More on Unicode Text
129(1)
The considering and ignoring Statements
130(5)
Combining Attributes
132(1)
Try It Out: Using considering and Ignoring Statements
133(2)
Words, Characters, and Paragraphs
135(10)
Working with Elements
136(2)
Try It Out: Working with Character Elements
138(2)
Try It Out: Working with Word Elements
140(3)
Try It Out: Picking a Random Element
143(1)
Understanding Text Item Delimiters
143(1)
Try It Out: Working with text Item delimiters
144(1)
Locating Strings inside Strings
145(4)
Try It Out: Using Containment Operators and the offset Command
146(3)
Specifying a Range to Get a Substring
149(1)
More on the Count Command
149(4)
Try It Out: Count the Number of Words in Some Text
150(1)
Using length instead of count
150(1)
Try It Out: Enumerating the Words in a String
151(1)
A Quick Note on References
152(1)
Enhancing the Alarm Clock Program
153(5)
Try It Out: Enhancing the Alarm Clock Program
154(4)
Summary
158(1)
Exercises
158(3)
Working with Lists and Records
161(50)
Working with Lists
161(35)
Empty Lists
163(1)
Counting the Number of Items in a List
163(1)
Accessing the Items in a List
164(1)
Try It Out: Working with List Items
165(3)
Try It Out: Sequencing through the Items In a List
168(1)
Try It Out: A Program to Display Populations of U.S. Cities
169(3)
Try It Out: A Modified Version of the Population Program
172(2)
The choose from list Command
174(1)
Try It Out: Looking Up the choose from list Command In the Dictionary
174(1)
Try It Out: Using the choose from list Command
175(3)
Accessing Items by Class
178(2)
Enumerating Lists: A Quick Review
180(1)
The rest and reverse Properties
180(1)
Try It Out: Exercising List Properties
180(1)
Modifying Lists
181(2)
Try It Out: Modifying List Items
183(3)
Try It Out: Deleting and Inserting items In a List
186(6)
Using Containment Operators with Lists
192(1)
Multiple Assignments with Lists
193(1)
List Coercions
194(1)
A Quick Note about Efficiency and Large Lists
195(1)
Working with Records
196(11)
Defining a Record
196(2)
The result Record from the display dialog Command
198(1)
Working with Lists of Records
198(2)
Try It Out: A Version of the Population Program Using Records
200(3)
Modifying Records
203(2)
Retrieving Multiple Properties
205(1)
Using the Containment Operators with Records
206(1)
Summary
207(1)
Exercises
207(4)
Working with Files
211(32)
Path Names: Traditional Mac and Posix-style
211(3)
Full Path Names
212(1)
Relative Path Names
212(1)
File Name Extensions
213(1)
What's in a Name?
214(1)
The file Class
214(1)
File Name Aliases
214(1)
Reading and Writing Files
215(16)
Try It Out: Creating a File In AppleScript
216(3)
The open for access Command
219(1)
Writing Data with the write Command
220(1)
Closing a File with the close Command
221(1)
Getting Information about a File or Folder Using the info for Command
221(1)
Reading Data with the read Command
222(1)
Try It Out: Reading Data from a File
222(3)
Try It Out: Using Various read Command Parameters
225(3)
More on Using the write Command
228(1)
Try It Out: Writing and Reading a List of Records
229(2)
Truncating a File Using the set eof Command
231(1)
Getting the Size of a File Using the get eof Command
231(1)
Appending Data to the End of a File
231(1)
Enumerating Disks and Folders
231(10)
Try It Out: Using the list folder Command
232(3)
Try It Out: Using the choose file Command
235(1)
Using the choose file Command to Pick a File
235(2)
Using the choose folder Command to Pick a Folder
237(1)
Using the choose file name Command to Pick a File Name
238(1)
Try It Out: Generating a List of Files for Backup
238(3)
Summary
241(1)
Exercises
241(2)
Handlers
243(40)
Writing a Handlers
243(2)
Try It Out: Writing Your First Handler
243(2)
Passing Parameters to Handlers
245(2)
Try It Out: Passing Parameters to Handlers
245(2)
Returning Handler Results
247(2)
Try It Out: Returning Values from Handlers
247(2)
Argument Types
249(1)
Local Variables
250(2)
Try It Out: Local Variables
250(2)
Call by Value
252(5)
Try It Out: Understanding Call by Value
252(5)
Recursive Handlers
257(5)
Try It Out: Recursive Factorial Handler
257(2)
Try It Out: A Recursive List Sort Handler
259(3)
Local/Global Variables and Variable Scope
262(7)
Try It Out: Local versus Global Variables
263(2)
Try It Out: Understanding Variable Scope: Protecting a Global Variable
265(1)
Try It Out: Understanding Variable Scope: Local and Global Variables with the Same Name (Part 1)
265(1)
Try It Out: Understanding Variable Scope: Local and Global Variables with the Same Name (Part 2)
266(1)
Try It Out: Understanding Variable Scope: Accessing a Global Variable Declared Outside a Handler
267(1)
Try It Out: Writing General Purpose Handlers
268(1)
Saving and Loading Handlers
269(3)
Try It Out: Saving and Loading the List Handlers
269(3)
The Apostrophe-s notation
272(1)
Labeled Parameters
272(6)
Try It Out: Writing a Handler with Labeled Parameters-Form 1
273(1)
Identifying Parameters with Prepositions
274(1)
Try It Out: Writing a Handler with Labeled Parameters-Form 2
275(1)
Combining Labeled Parameter Formats
275(1)
Specifying a Direct Parameter
276(1)
Using with and without for Boolean Parameters
277(1)
Specifying Patterns for Parameters
278(2)
Summary
280(1)
Exercises
281(2)
Error Handling
283(18)
Beeps and Dialogs
283(1)
The try...on error Statement
284(8)
More on the on error Clause
285(1)
Try It Out: Experimenting with Errors
286(1)
Try It Out: Identifying Errors by Number
287(2)
Catching a Specific Error by Number
289(1)
More on Error Numbers and Error-Handling Strategy
290(2)
The error Command
292(6)
Try It Out: Catching Errors In Your Handlers
293(3)
Try It Out: Error-Proofing Your Code
296(2)
Summary
298(1)
Exercises
299(2)
Working with Applications
301(54)
Talking to Other Applications: The tell Statement
301(16)
Try It Out: Using the tell Statement
302(2)
Try It Out: References to Objects and More on the tell Statement
304(2)
Try It Out: Sliding Windows
306(1)
Try It Out: Stacking Windows
307(2)
The One-Liner tell Statement
309(1)
More on Targets
309(1)
Try It Out: Understanding Targets-Part 1
309(1)
Try It Out: Understanding Targets-Part 2
310(1)
Using my, me, and its inside tell Blocks
311(1)
Try It Out: Calling Handlers from within tell Blocks
312(1)
Try It Out: Accessing Properties or Variables from within tell Blocks-Part 1
313(1)
Try It Out: Accessing Properties or Variables-Part 2
314(1)
Tell Me Some More
315(2)
More on Working with the Finder
317(21)
Looking at the Finder's Dictionary in Greater Detail
317(1)
Try It Out: Examining the Finder's Dictionary
317(4)
The Finder's Classes
321(1)
Containers
322(1)
Try It Out: Learning about Containers--Part 1
322(1)
Try It Out: Learning about Containers--Part 2
322(1)
Try It Out: Learning about Containers--Part 3
323(1)
Try It Out: Learning about Containers--Part 4
323(1)
Try It Out: Learning about Containers--Part 5
324(1)
Common File Operations
324(1)
Common Folder Operations
325(3)
Try It Out: Getting a List of Containers
328(1)
Try It Out: A List of Containers as Allases
328(1)
Try It Out: Adding a Prefix to Each File in a Folder
329(2)
More on Understanding Finder File References
331(1)
Try It Out: Understanding File References
331(1)
Try It Out: Using Finder Filer References outside a tell Block
332(1)
Beware of the repeat-with Statement!
333(1)
AppleScript versus the Finder's File Class
334(2)
Filters
336(1)
Try It Out: Using a Filter
336(2)
More on Working with Applications
338(5)
Try It Out: Generating a List of Backup Files
338(4)
Ignoring Application Responses
342(1)
Application Timeouts
343(1)
Applets and Droplets
343(8)
Stay Open Applications
344(1)
The run Handler
344(1)
The quit Handler
344(1)
The reopen Handler
344(1)
The idle Handler
345(1)
Try It Out: Simple Applet Handlers
345(2)
Droplets
347(1)
Try It Out: Creating a Droplet
347(4)
Summary
351(1)
Exercises
352(3)
Scripting iLife Applications
355(30)
Scripting iTunes
356(10)
Try It Out: Examining the iTunes Dictionary
356(3)
Working with Tracks and Playlists
359(4)
An iTunes Player Applet
363(1)
Try It Out: An iTunes Song Player
363(3)
Scripting iPhoto
366(6)
Try It Out: Examining iPhoto's Dictionary
367(1)
Try It Out: Making an Album from a Folder of Images
368(4)
Scripting iDVD
372(10)
Try It Out: Examining iDVD's Dictionary
372(3)
Try It Out: Making a DVD Slide Show from a Folder of Images
375(7)
Summary
382(1)
Exercises
382(3)
Script Objects
385(34)
Defining a Script Object
385(1)
Try It Out: Defining a Script Object
385(1)
Script Properties
386(4)
Try It Out: Working with Script Properties
387(1)
Initializing Script Properties
387(1)
Try It Out: Initializing Script Properties
388(1)
Copying Script Objects
389(1)
Try It Out: Copying Script Objects
389(1)
Your Program Is a Script Object
390(4)
Try It Out: Defining Properties at the Top Level
390(1)
Try It Out: Properties in Applications
391(1)
Try It Out: Recording Values in Applications
392(1)
Scope of Properties
393(1)
Try It Out: Scope of Script Properties
393(1)
pi Is a Property
394(1)
Script Objects Containing Handlers
394(3)
Try It Out: Defining Handlers Inside Scripts
395(1)
The Run Handler
396(1)
Handlers Containing Script Objects
397(2)
Try It Out: Defining Script Objects Inside Handlers
397(2)
Storing, Loading, and Running Scripts from Files
399(2)
Try It Out: Illustrating the store script and run script Commands
399(1)
Try It Out: Running and Loading a Script
400(1)
Script Objects and Object-Oriented Programming
401(14)
Try It Out: Returning a Script Object from a Handler
402(1)
Try It Out: More on Returning Script Objects
403(2)
Try It Out: Defining a Rectangle Object
405(2)
Polymorphism
407(1)
Try It Out: Polymorphism In AppleScript
407(2)
Inheritance
409(1)
Try It Out: Illustrating Inheritance
410(2)
Try It Out: Defining a Square Using Inheritance
412(1)
Using its in Inherited Handlers
413(1)
Try It Out: Using my in Handlers
413(1)
The continue Command
414(1)
Try It Out: Calling a Parent's Handler Using the continue Command
414(1)
Summary
415(1)
Exercises
416(3)
Loose Ends
419(30)
Command Handlers
419(1)
Try It Out: Writing a Command Handler
420(1)
Using terms from
420(1)
Using the clipboard
421(2)
The Script Menu
423(1)
Folder Actions
424(3)
Try It Out: Working with Folder Actions
425(2)
Open Scripting Architecture
427(2)
Scripting Additions
429(1)
AppleEvents
429(1)
Try It Out: AppleEvents in the Event Log History
429(1)
Recording Scripts
430(2)
Try It Out: Recording Actions in the Finder
430(2)
GUI Scripting
432(2)
Try It Out: Introduction to GUI Scripting
432(2)
Before and After
434(1)
Creating a Reference to an Object
434(1)
Web Services: XML-RPC and SOAP
435(3)
Try It Out: Using SOAP Services
437(1)
Running Scripts from Terminal
438(1)
The do shell script Command
439(2)
The with transaction Statement
441(1)
Delayed Evaluation with the run script Command
441(1)
Scheduling Scripts to Run with the cron
442(3)
Try It Out: Chime the Hour!
442(3)
Summary
445(1)
Exercises
446(3)
Introducing AppleScript Studio
449(24)
Installing AppleScript Studio
449(1)
Developing a Simple Application
450(19)
Try It Out: Working with AppleScript Studio
451(18)
An iTunes Remote
469(1)
Summary
470(1)
Exercises
471(2)
Appendix A: Exercise Answers
473(52)
Appendix B: Language Reference
525(30)
Operators
525(3)
English Equivalents of Relational Operators
526(1)
Containment Operators
527(1)
Built-in Classes
528(2)
Classes of Weights and Measures
530(1)
Lists
530(1)
List Class Properties
530(1)
Element Specifiers
531(1)
Records
531(1)
Record Class Properties
531(1)
Strings
532(1)
String Class Properties
532(1)
Predefined String Properties
532(1)
Escape Characters
532(1)
String Elements
533(1)
Dates
533(1)
Date Class Properties
533(1)
Predefined Properties for Working with Dates
534(1)
Compound Statements
534(4)
considering
534(1)
if
535(1)
ignoring
536(1)
repeat
536(1)
tell
537(1)
try
537(1)
using terms from
537(1)
with timeout
537(1)
with transaction
538(1)
Commands
538(17)
activate
539(1)
adding folder items to*
539(1)
ASCII character*
540(1)
ASCII number*
540(1)
choose application*
540(1)
choose color*
540(1)
choose file*
540(1)
choose file name*
541(1)
choose folder*
541(1)
choose from list*
541(1)
choose URL*
541(1)
clipboard info*
541(1)
close access*
542(1)
closing folder window for*
542(1)
continue
542(1)
copy
542(1)
count
542(1)
current date*
543(1)
delay*
543(1)
display dialog*
543(1)
do shell script*
543(1)
error
544(1)
exit repeat
545(1)
get
545(1)
get eof*
545(1)
get volume settings*
545(1)
handle CGI request*
545(1)
info for*
546(1)
launch
546(1)
list disks*
546(1)
list folder*
546(1)
load script *
546(1)
log
547(1)
mount volume*
547(1)
moving folder window for*
547(1)
offset*
547(1)
open for access*
547(1)
open location*
548(1)
opening folder*
548(1)
path to*
548(1)
random number*
548(1)
read*
549(1)
removing folder items from*
549(1)
return
549(1)
round*
550(1)
run script*
550(1)
say*
550(1)
scripting components*
550(1)
set
551(1)
set eof*
551(1)
set the clipboard to*
551(1)
set volume*
551(1)
start log
551(1)
stop log
552(1)
store script*
552(1)
summarize*
552(1)
system attribute*
552(1)
the clipboard*
552(1)
time to GMT*
553(1)
write*
553(2)
Appendix C: Resources
555(4)
Errata, etc.
555(1)
AppleScript Books
555(1)
Websites
556(1)
Mailing Lists and Newsgroups
556(1)
Development Tools
557(2)
AppleScript Studio
557(1)
Script Editor
558(1)
Smile
558(1)
Script Debugger 3.0
558(1)
Index 559

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Rewards Program