AppleScript 2nd Edition.pdf

(16213 KB) Pobierz
374313351 UNPDF
THE EXPERT’S VOICE ® IN MAC DEVELOPMENT
AppleScript
The Comprehensive Guide to Scripting
and Automation on Mac OS X
Everything you could ever need to know about AppleScript!
SECOND EDITION
Hanaan Rosenthal
374313351.040.png 374313351.051.png 374313351.061.png 374313351.062.png 374313351.001.png 374313351.002.png 374313351.003.png 374313351.004.png 374313351.005.png 374313351.006.png 374313351.007.png 374313351.008.png 374313351.009.png 374313351.010.png 374313351.011.png 374313351.012.png 374313351.013.png 374313351.014.png 374313351.015.png 374313351.016.png 374313351.017.png 374313351.018.png 374313351.019.png 374313351.020.png 374313351.021.png 374313351.022.png 374313351.023.png
 
374313351.024.png
 
374313351.025.png
 
374313351.026.png
 
374313351.027.png
 
374313351.028.png 374313351.029.png 374313351.030.png 374313351.031.png 374313351.032.png 374313351.033.png 374313351.034.png 374313351.035.png 374313351.036.png 374313351.037.png 374313351.038.png
 
374313351.039.png 374313351.041.png 374313351.042.png 374313351.043.png 374313351.044.png 374313351.045.png 374313351.046.png 374313351.047.png 374313351.048.png 374313351.049.png 374313351.050.png 374313351.052.png 374313351.053.png 374313351.054.png
AppleScript
The Comprehensive Guide to
Scripting and Automation on
Mac OS X, Second Edition
Hanaan Rosenthal
374313351.055.png 374313351.056.png 374313351.057.png
AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Second Edition
Copyright © 2006 by Hanaan Rosenthal
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-653-1
ISBN-10 (pbk): 1-59059-653-6
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Chris Mills
Technical Reviewer: Hamish Sanderson
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft,
Jim Sumser, Keir Thomas, Matt Wade
Project Manager: Beth Christmas
Copy Edit Manager: Nicole LeClerc
Copy Editor: Kim Wimpsett
Assistant Production Director: Kari Brooks-Copony
Production Editor: Ellie Fountain
Compositor: Dina Quan
Proofreader: Lori Bring
Indexer: John Collin
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com , or
visit http://www.springeronline.com .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com , or visit http://www.apress.com .
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indi-
rectly by the information contained in this work.
The source code for this book is available to readers at http://www.customflowsolutions.com and at
http://www.apress.com in the Source Code/Download section.
374313351.058.png
374313351.059.png
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxii
PART 1
■ ■ ■ Read Me First
CHAPTER 1
Introducing AppleScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
PART 2 ■ ■ ■ How to AppleScript
CHAPTER 2 Scripting—From the Ground Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CHAPTER 3 Introducing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
CHAPTER 4 Doing the Math: All About Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
CHAPTER 5 Picking Up Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
CHAPTER 6 Working with Lists and Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
CHAPTER 7 Giving Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
CHAPTER 8 Working with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
CHAPTER 9 Introducing Operations and Coercion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
CHAPTER 10 Teaching Your Script to Make Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
CHAPTER 11 The Assembly Line: Creating Repeat Loops . . . . . . . . . . . . . . . . . . . . . . . . . 273
CHAPTER 12 Interacting with the User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
CHAPTER 13 Advanced User Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
CHAPTER 14 Working with Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
CHAPTER 15 Manipulating the File System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
CHAPTER 16 Working with the Clipboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
CHAPTER 17 Using Errors to Your Advantage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
CHAPTER 18 Defining and Calling Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
CHAPTER 19 Using Script Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
iv
374313351.060.png
Zgłoś jeśli naruszono regulamin