Applescript: the Missing Manual by Adam Goldstein Publisher
Total Page:16
File Type:pdf, Size:1020Kb
AppleScript: The Missing Manual By Adam Goldstein Publisher: O'Reilly Pub Date: February 2005 ISBN: 0-596-00850-3 Pages: 350 Table of • Contents • Index • Reviews • CD-ROM AppleScript: The Missing Manual is every beginner's guide to learning the Reader Macintosh's ultimate scripting tool: AppleScript. Through dozens of hands- • Reviews on scripting examples, this comprehensive guide ensures that anyone • Errata including novices can learn how to control Mac applications in timesaving • Academic and innovative ways. Thanks to AppleScript: The Missing Manual, the path Top Ten from regular Mac fan to seasoned scripter has never been easier. • AppleScript Tips AppleScript: The Missing Manual By Adam Goldstein Publisher: O'Reilly Pub Date: February 2005 ISBN: 0-596-00850-3 Pages: 350 Table of • Contents • Index • Reviews • CD-ROM Reader • Reviews • Errata • Academic Top Ten • AppleScript Tips Copyright The Missing Credits About the Author About the Creative Team Acknowledgments The Missing Manual Series Foreword Introduction Uses for AppleScript Advantages and Disadvantages About This Book Part I: AppleScript Overview Chapter 1. Setting Up AppleScript Section 1.1. The Script Menu Section 1.2. Working with the Scripts You Have Chapter 2. Using Script Editor Section 2.1. The Script Editor Look Section 2.2. Script Formats Section 2.3. Setting Script Editor's Preferences Chapter 3. Building a Script from Scratch Section 3.1. Getting Started Section 3.2. Commanding Other Programs Part II: Everyday Scripting Tasks Chapter 4. Manipulating Text Section 4.1. String Notation Section 4.2. Getting Text Back from Dialog Boxes Section 4.3. Linking Strings Together Section 4.4. Multiline Strings Section 4.5. Scripting TextEdit Section 4.6. Adding Word Count Section 4.7. Commanding Microsoft Word Section 4.8. Running Scripts from Text Chapter 5. Controlling Files Section 5.1. File Path Boot Camp Section 5.2. Displaying Folders Section 5.3. Moving Files Around Section 5.4. Backing Up Files Section 5.5. Deleting Files Section 5.6. Picking a File from a Dialog Box Section 5.7. Saving Files Chapter 6. Creating Lists Section 6.1. Common List Commands Section 6.2. Displaying Lists Section 6.3. The Ever-Useful every Keyword Section 6.4. List Processing Section 6.5. Joining Lists Together Section 6.6. Inputting Lists Section 6.7. Getting Lists from Other Programs Chapter 7. Organizing and Editing Graphics Section 7.1. Scripting iPhoto Section 7.2. Controlling Photoshop Section 7.3. Image Events Chapter 8. Playing Sound and Video Section 8.1. Scripting iTunes Section 8.2. Speaking and Listening Section 8.3. Scripting QuickTime Chapter 9. Internet and Network Scripting Section 9.1. Internet Connect Section 9.2. Safari Section 9.3. Address Book Section 9.4. Mail Section 9.5. iChat Control Section 9.6. URL Access Scripting Section 9.7. Recalling Passwords Chapter 10. Organizing Information in Databases Section 10.1. Record Notation Section 10.2. Making a Simple AppleScript Database Section 10.3. Getting File Information Section 10.4. Scripting FileMaker Pro Part III: Power-User Features Chapter 11. Linking Scripts to Folders with Folder Actions Section 11.1. Enabling Folder Actions Section 11.2. Built-in Actions Section 11.3. Running Your Own Actions Chapter 12. Scripting Programs That Don't Have Dictionaries Section 12.1. Enabling GUI Scripting Section 12.2. GUI Scripting Basics Section 12.3. Controlling Menus Section 12.4. Clicking Buttons Section 12.5. Deciphering Interface Hierarchies Section 12.6. Fake Typing Chapter 13. Mixing AppleScript and Unix Section 13.1. Terminal Section 13.2. Unix Without Terminal Section 13.3. Running Superuser Commands Section 13.4. Running AppleScripts from Unix Section 13.5. Scheduling AppleScript Commands Chapter 14. Testing and Debugging Scripts Section 14.1. First Line of Defense: The Compiler Section 14.2. Noting Important Events Section 14.3. Preventing Errors Section 14.4. Isolating and Handling Errors Section 14.5. The Xcode Debugger Chapter 15. AppleScript Studio Section 15.1. What Is AppleScript Studio? Section 15.2. Making a Program Part IV: Appendixes Appendix A. AppleScript Support in Common Programs Section A.1. Databases Section A.2. Email Programs Section A.3. Graphics Editors Section A.4. Page Layout Programs Section A.5. Plain Text Editors Section A.6. Word Processors Section A.7. Web Browsers Appendix B. Moving from HyperCard to AppleScript Section B.1. Data Types Section B.2. Dialog Boxes Section B.3. Existence Section B.4. Numbers Section B.5. Pausing Section B.6. Ranges Section B.7. Repeat Statements Section B.8. Subroutines Section B.9. Variables Appendix C. Where to Go from Here Section C.1. Web Sites Section C.2. Discussion Lists Section C.3. Books Colophon Index Copyright © 2005 O'Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 [email protected] . Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. AppleScript: The Missing Manual, The Missing Manual logo, Pogue Press, the Pogue Press logo, and "The book that should have been in the box" are trademarks of O'Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. The Missing Credits About the Author About the Creative Team Acknowledgments The Missing Manual Series About the Author Adam Goldstein is the teenage founder of GoldfishSoft (www.goldfishsoft.com), a software company specializing in games and utilities for Mac OS X. He has worked on several books for O'Reilly, including Mac OS X: The Missing Manual (as technical editor) and Mac OS X Power Hound (as co-editor). In his spare time, Adam attends high school in New Jersey, where he is a captain of the Quizbowl team and is engaged in various other nerdy endeavors. He welcomes feedback about this book by email: [email protected]. (If you need technical help, however, please refer to the sources in Appendix C.) About the Creative Team Chuck Toporek (editor) is the author of Inside .Mac, the Mac OS X Panther Pocket Guide (and all its previous incarnations for earlier versions of Mac OS X), and is a coauthor ofMac OS X Panther in a Nutshell. He's a senior editor with O'Reilly Media, Inc., responsible for all of the non-Missing Manual Mac OS X-related books published by O'Reilly. Chuck resides in Portland, Oregon, where he spends his free time sipping coffee and enjoying the grandeur of the Pacific Northwest. Email: [email protected]. Web: http://homepage.mac.com/chuckdude. Rose Cassano (cover illustration) has worked as an independent designer and illustrator for 20 years. Assignments have ranged from the nonprofit sector to corporate clientele. She lives in beautiful Southern Oregon, grateful for the miracles of modern technology that make working there a reality. Email: [email protected]. Web: www.rosecassano.com. Ellie Volckhausen (cover designer) has been at O'Reilly for several years, and has discovered that the sooty phalangist from Van Diemen's Land is the same animal as the Common Brushtail Possum from Tasmania. Paul Berkowitz (technical reviewer) has tech-edited other O'Reilly AppleScript books, including AppleScript: The Definitive Guide by Matt Neuburg, and has also done some technical proofreading of AppleScript-related documentation for Apple and Microsoft. He is the author of the AppleScript chapter in Office 2004 for the Mac: The Missing Manual. He is well known as the author of over 100 AppleScripts for Entourageincluding major script programs for exporting and importing just about everythingand programs for syncing Entourage to Apple's Address Book and iCal. In his "other life," he is a classical pianist and Professor of Piano at the University of California in Santa Barbara, where he now lives happily ever after. John Gruber (technical reviewer) is a freelance writer, Web developer, designer, and Mac nerd. He combines those interests on his Web site, Daring Fireball (http://daringfireball.net), which is widely regarded as "not bad." John lives in Philadelphia with his lovely wife, Amy, and their young son Jonas. Lydian Meredith (technical reviewer) has been working and playing with Macs since 1988, in academia, business, and publishing. Currently she runs her own publishing bureau in London and lurks in several Mac User lists, including some for AppleScript. August Trometer (technical reviewer) is the creator and developer of the podcasting client iPodderX, as well as the creator and administrator of the .Mac portal Web site,dotmac.info . A former restaurant owner, he now works as a software and Web developer. He lives in Indianapolis, Indiana. Email: [email protected]. Web: http://dotmac.info. Linley Dolby (copyeditor) spent several years in the production department at O'Reilly before moving to Martha's Vineyard to pursue a freelance career. She now helps whip technical books into shape for several companies, including O'Reilly and Pogue Press. Email:[email protected] . Genevieve d'Entremont (production editor) has been at O'Reilly for two years now, but she still doesn't understand why people are so fascinated by technological minutiae.