Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition (Learn Series)
معرفی کتاب «یادگیری اپلاسکریپت: راهنمای جامع برای اسکریپتنویسی و اتوماسیون در مک او اس ایکس (ویرایش سوم)» (با عنوان لاتین Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition (Learn Series)) نوشتهٔ Hanaan Rosenthal, Hamish Sanderson، منتشرشده توسط نشر Apress : Imprint: Apress در سال 2010. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.
«یادگیری اپلاسکریپت: راهنمای جامع برای اسکریپتنویسی و اتوماسیون در مک او اس ایکس (ویرایش سوم)» نوشتهٔ هامیش ساندرسون و حنان روزنتال، یکی از کاملترین و معتبرترین منابع برای تسلط بر زبان اسکریپتنویسی اپل است. این کتاب که توسط انتشارات آپرس (Apress) منتشر شده، با بیش از هزار صفحه محتوای تخصصی، راهنمایی گامبهگام برای خودکارسازی وظایف در سیستمعامل مک، از سادهترین کارهای تکراری تا پیچیدهترین گردشهای کاری، ارائه میدهد.
دربارهٔ کتاب یادگیری اپلاسکریپت: راهنمای جامع برای اسکریپتنویسی و اتوماسیون در مک او اس ایکس (ویرایش سوم)
کتاب «یادگیری اپلاسکریپت» به عنوان یک منبع جامع و در عین حال کاربردی، به تمامی ابعاد این زبان اسکریپتنویسی انگلیسیگونه و قدرتمند که در تمامی رایانههای مک تعبیه شده است، میپردازد. این ویرایش سوم که بهروزرسانی شده تا با سیستمعامل Mac OS X Snow Leopard سازگار باشد، بر ارائهٔ اطلاعات عملی و قابلاستفاده برای حل هر نوع مشکل اتوماسیون تأکید دارد. نویسندگان کتاب با رویکردی آموزشی و ساختاریافته، مفاهیم بنیادین تا پیشرفته را پوشش میدهند و خواننده را با نحوهٔ اسکریپتنویسی برای برنامههای کاربردی مختلف آشنا میسازند. این کتاب با مقدمهای بر اصول اولیه و چیستی اپلاسکریپت آغاز شده و در بخش دوم، به درک عمیقتر از این زبان و نحوهٔ کارکرد آن میپردازد. در نهایت، بخش سوم کتاب به کاربردهای عملی و پروژههای واقعی اختصاص دارد که به خواننده کمک میکند دانش خود را در عمل به کار گیرد. سبک نگارش کتاب بهگونهای است که برای افراد مبتدی نیز قابل درک بوده، در عین حال مطالب پیشرفتهای را برای کاربران حرفهای و باتجربه اپلاسکریپت فراهم میآورد. مشارکت متخصصان برجستهٔ این حوزه مانند امانوئل لوی، شین استنلی و بری وینرایت که هر یک بخشهایی از کتاب را نگاشتهاند، بر غنای محتوایی آن افزوده است.
دربارهٔ نویسنده
هامیش ساندرسون، یکی از نویسندگان اصلی این کتاب، یک متخصص و کهنهکار حرفهای در زمینهٔ اپلاسکریپت با بیش از ده سال سابقه است که در بریتانیا زندگی و کار میکند. او در طول سالها کتابخانهها و ابزارهای مفید بسیاری را در اختیار جامعهٔ کاربران اپلاسکریپت قرار داده و به طور منظم در انجمنهای گفتگوی مرتبط با این زبان شرکت دارد. از جمله دستاوردهای مهم او، کتابخانهٔ اپاسکریپت (appscript) است که امکان اسکریپتنویسی به سبک اپلاسکریپت را برای زبانهای برنامهنویسی پایتون، روبی و آبجکتیو-سی فراهم میکند. حنان روزنتال نیز نویسندهٔ دیگر این کتاب است که به عنوان سخنران در نمایشگاههای معتبری مانند MacWorld Expo و Seybold Seminars فعالیت داشته است.
چرا باید یادگیری اپلاسکریپت: راهنمای جامع برای اسکریپتنویسی و اتوماسیون در مک او اس ایکس (ویرایش سوم) را بخوانید؟
با مطالعهٔ این کتاب، بینشها و مهارتهای کلیدی زیر را کسب خواهید کرد:
درک ساختار و مفاهیم بنیادی اپلاسکریپت: با نحوهٔ نمایش اطلاعات به صورت اشیاء، کار با دستورات و عملگرها، و ساختار برنامهنویسی این زبان آشنا میشوید.
توانایی خودکارسازی وظایف از ساده تا پیچیده: میآموزید که چگونه کارهای تکراری و زمانبر را به اپلاسکریپت بسپارید و گردشهای کاری یکپارچه و کارآمد ایجاد کنید.
کار با برنامههای قابل اسکریپتنویسی: یاد میگیرید که چگونه با برنامههای مختلفی که از اپلاسکریپت پشتیبانی میکنند، ارتباط برقرار کرده و آنها را کنترل نمایید.
پیادهسازی پروژههای عملی: کتاب با پروژههای واقعی مانند «تیدِی دسکتاپ» (Tidy Desktop)، شما را در مسیر عملیسازی دانش تئوری هدایت میکند و مهارتهای حل مسئله را در شما تقویت میکند.
استفاده از تکنیکهای پیشرفته و عیبیابی: با مطالعهٔ بخشهای تخصصی که توسط متخصصان برجسته نوشته شده، با پیچیدگیهای این زبان و روشهای رفع خطا آشنا میشوید.
این کتاب برای چه کسانی مناسب است؟
دامنهٔ مخاطبان این کتاب بسیار گسترده است و از کاربران خانگی مک که میخواهند با خودکارسازی کارهای روزمره، زمان خود را مدیریت کنند، تا مدیران سیستم و توسعهدهندگان حرفهای را در بر میگیرد. همچنین، این منبع برای برنامهنویسانی که با زبانهای دیگر کار میکنند و میخواهند دانش خود را در زمینهٔ اسکریپتنویسی در محیط مک گسترش دهند، بسیار ارزشمند است. به دلیل ساختار آموزشی و پوشش جامع مباحث، کتاب برای افراد مبتدی که هیچ پیشزمینهای در برنامهنویسی ندارند نیز مناسب بوده و در عین حال، مطالب عمیق و پیشرفتهای برای متخصصان باتجربه ارائه میدهد تا به عنوان یک مرجع کامل از آن استفاده کنند.
سوالات متداول
آیا برای استفاده از این کتاب نیاز به دانش قبلی در برنامهنویسی دارم؟
خیر، یکی از نقاط قوت این کتاب، زبان ساده و روان آن است که مفاهیم را از سطح پایه آموزش میدهد. نویسندگان با فرض عدم آشنایی خواننده با برنامهنویسی، مبانی را گامبهگام توضیح دادهاند، اگرچه وجود ذهنیت منطقی میتواند به درک بهتر مطالب کمک کند.
آیا مطالب کتاب برای آخرین نسخهٔ سیستمعامل مک بهروز است؟
این کتاب به طور خاص برای سیستمعامل Mac OS X Snow Leopard (نسخهٔ.۶) بهروزرسانی و منتشر شده است. با توجه به اینکه تاریخ انتشار کتاب در سال ۲۰۱۰ است، مفاهیم بنیادین اپلاسکریپت که در این کتاب آموزش داده شدهاند، همچنان معتبر و قابل استفاده بوده و پایهای مستحکم برای کار با نسخههای جدیدتر این زبان فراهم میکنند.
آیا کتاب به مباحث عملی و پروژهمحور نیز میپردازد؟
بله، کتاب با تأکید بر اطلاعات عملی نوشته شده و شامل پروژههای واقعی و مثالهای متعدد است که به خواننده کمک میکند تا آموختههای خود را در عمل پیادهسازی کند. بخش سوم کتاب به طور خاص به کاربردهای عملی و حل مسائل واقعی با اپلاسکریپت اختصاص دارد.
Wow! Leonard Rosenthal and Hamish Sanderson have written what has to be the definitive book on AppleScript. I almost do not where to begin with this review; The book covers literally everything about AppleScript in an easy to understand manner, with a plethora of examples. It does not get bogged down in theory, although it covers theory more than adequately. I've been writing applescripts since the language first came out, and if I could have only one reference and tutorial for the language, this would be it. Prelim......Page 1 Contents at a Glance......Page 5 Contents......Page 7 Foreword......Page 21 About the Authors......Page 23 About the Technical Reviewer......Page 24 Acknowledgments......Page 25 Introduction......Page 26 Part 1: Welcome to AppleScript......Page 31 Automating Small Tasks......Page 33 Automating Large Tasks......Page 34 When to Automate (or Not)?......Page 35 What Is a Scriptable Application?......Page 36 What Is the AppleScript Language?......Page 38 What Is a Script?......Page 39 Your First AppleScript: Hello World!......Page 40 Summary......Page 43 AppleScript in Principle......Page 45 How Applications Represent Information As Objects......Page 46 How Applications Manipulate Objects Using Commands......Page 48 How Applications Organize Their Objects into Object Models......Page 49 How Applications Describe Their Objects and Commands in Dictionaries......Page 51 The Four Key Concepts of the AppleScript Language......Page 52 How AppleScript Represents Information As Objects......Page 53 How AppleScript Manipulates Objects Using Commands, Operators, and Variables......Page 54 How AppleScript Makes Decisions on What to Do and When to Do It......Page 55 How AppleScript Organizes Code Using Handlers and Script Objects......Page 56 The English-like Syntax......Page 58 Attaching Scripts to Applications......Page 59 The AppleScript Community......Page 60 Summary......Page 61 The Project: Tidy Desktop......Page 63 Planning the Script......Page 64 Creating the Folder Name......Page 65 Interacting with the File System......Page 69 Improving Reliability......Page 76 Adding Features......Page 77 Documenting Your Code......Page 78 Summary......Page 79 Part 2: Understanding AppleScript......Page 81 Working with Script Windows......Page 83 Compiling a Script......Page 84 Recording a Script......Page 85 Viewing the Events Sent by a Running Script......Page 86 Viewing Application Dictionaries......Page 87 Other Useful AppleScript Editor Features......Page 88 Using the Library Window......Page 89 Navigating to a Handler in a Script......Page 90 Scripting the AppleScript Editor......Page 91 Viewing the Bundle Contents Drawer......Page 92 Setting the Script Formatting Preferences......Page 93 Saving Scripts......Page 95 Compiled Scripts......Page 96 Script-Based Applications (Applets)......Page 99 The System-wide Script Menu......Page 102 Third-Party AppleScript Editors......Page 104 Summary......Page 106 Understanding How Application Scripting Works......Page 107 A Quick Application Scripting Example......Page 108 How Objects Are Categorized by Class......Page 109 Introducing Object Properties......Page 111 Introducing Object Elements......Page 114 Understanding Commands......Page 116 Introducing Command Parameters......Page 117 Commands Must Be Targeted at Objects......Page 119 Commands Can Return Results or Report Errors......Page 120 Understanding the Application Object Model......Page 121 How Objects Can Contain Other Objects......Page 122 How AppleScript Refers to Application Objects......Page 123 Exploring a Typical Object Model......Page 128 Understanding Application Dictionaries......Page 133 Introducing AppleScript Editor’s Dictionary Viewer......Page 134 How Classes Are Documented......Page 137 How Commands Are Documented......Page 148 Application Dictionaries Don’t Tell You Everything!......Page 150 Creating application Objects......Page 153 The Standard Properties of application Objects......Page 156 How AppleScript Compiles tell application ... Blocks......Page 157 More on Constructing References......Page 158 Referring to Elements......Page 159 Referring to Insertion Locations......Page 168 Summary......Page 169 Learning to Work with AppleScript Objects......Page 173 What Kinds of Objects Does AppleScript Provide?......Page 174 Getting Information from Objects......Page 175 Manipulating Objects with Commands......Page 176 Manipulating Objects with Operators......Page 178 Coercing Objects......Page 183 Storing Objects in Variables......Page 184 Working with Boolean Objects......Page 187 Boolean Operators......Page 188 Boolean-Related Coercions......Page 190 Summary......Page 191 Introducing Text......Page 193 A Brief History of Text......Page 194 Introducing Text in AppleScript 2.0......Page 199 How to Write Literal Strings in AppleScript......Page 200 The id Property......Page 204 Characters......Page 205 Words......Page 208 Text Ranges......Page 209 Joining Strings......Page 211 Comparing Strings......Page 212 Checking for Strings Within Strings......Page 214 Considering and Ignoring Attributes......Page 215 The offset Command......Page 219 Coercing to and from Text......Page 220 Splitting Strings with Text Item Delimiters......Page 222 Combining List Items into a Single String......Page 224 Finding and Replacing Text......Page 226 How AppleScript Text Works in Tiger......Page 227 Working with the Various Text Classes......Page 228 The ASCII number and ASCII character Commands......Page 230 Example Projects......Page 231 Defining a Find-and-Replace Command......Page 232 Transferring Meeting Arrangements from Mail to iCal......Page 234 Summary......Page 243 Introducing Integers and Reals......Page 245 Operators and Commands......Page 246 Math Operations......Page 247 Comparison Operations......Page 251 Introducing Operator Precedence......Page 254 The round Command......Page 255 The random number Command......Page 257 Coercing to and from Numbers......Page 259 Defining a Round-to-Decimal-Places Command......Page 261 Blackjack!......Page 263 Kitchen Timer......Page 267 Summary......Page 270 Introducing Dates......Page 271 Understanding Date and Time Formats......Page 272 Forming Dates On-the-Fly......Page 274 Specifying a Time Relative to a Date......Page 276 The month Property......Page 277 The weekday Property......Page 278 The time Property......Page 279 Setting Date Properties......Page 280 Comparison Operators......Page 282 Math Operators......Page 284 The current date Command......Page 287 Example Projects......Page 288 Deleting Old Files......Page 289 Alarm Clock......Page 293 Summary......Page 296 What Is a List?......Page 297 What Is a Record?......Page 298 Working with Lists......Page 299 The Properties of a List......Page 300 The Elements of a List......Page 301 Operators and Commands......Page 304 Processing List Items with a Repeat Loop......Page 309 Sorting Items in a List......Page 311 Working with Records......Page 312 Getting and Setting the Properties of a Record......Page 314 Operators and Commands......Page 316 Planning the Script......Page 317 Developing the Script......Page 318 Conclusion......Page 321 Summary......Page 322 Creating Variables......Page 323 Declaring Your Variables......Page 324 Choosing Your Variable Names......Page 325 Working with Local Variables......Page 329 Understanding Local Variable Scope......Page 330 Passing Values to and from User-Defined Handlers......Page 333 Understanding Property and Global Variable Scope......Page 335 How Properties (and Global Variables) Can Retain Values Between Runs......Page 336 When to Use Properties and Global Variables......Page 337 Using AppleScript’s Built-in Variables......Page 340 Variables Containing Predefined Values......Page 341 Variables Containing Objects of Special Interest......Page 343 Summary......Page 348 Application-Defined Commands......Page 349 Scripting Addition Commands......Page 352 AppleScript Commands......Page 353 User-Defined Commands......Page 354 Picking the Right Target for Your Commands......Page 355 The set Command......Page 357 The copy Command......Page 358 The run Command......Page 360 The run Command......Page 361 The open Command......Page 362 The quit Command......Page 363 The get Command......Page 364 The set Command......Page 365 The make Command......Page 366 The count Command......Page 368 The move Command......Page 369 The duplicate Command......Page 370 The delete Command......Page 371 The print Command......Page 372 The save Command......Page 373 The close Command......Page 374 When Do Implicit get Commands Occur?......Page 375 When Are Explicit get Commands Necessary?......Page 377 Telling the Difference Between AppleScript and Application set Commands......Page 380 Getting and Setting Multiple Values in a Single Statement......Page 381 Using copy As an Application Command......Page 382 Considering and Ignoring Application Responses......Page 384 Controlling the Timeout Delay for Long-Running Commands......Page 387 Enabling Remote Apple Events......Page 389 Talking to Remote Machines......Page 391 Authenticating Access to Remote Machines......Page 392 Compiling Scripts Offline......Page 393 Targeting Remote Applications by User and Process IDs......Page 394 Summary......Page 396 Understanding the a reference to Operator......Page 399 Introducing Unit Type Conversions......Page 403 A Summary of AppleScript Coercions......Page 404 Coercing Class and Constant Names......Page 405 Coercing Numbers and Text......Page 406 Coercing File Objects......Page 407 Coercing Lists......Page 408 The Concatenation Operator......Page 409 Math Operators......Page 410 Comparison Operators......Page 411 Containment Operators......Page 412 The a reference to Operator......Page 413 Operator Precedence in Detail......Page 414 Understanding Precedence......Page 415 Understanding Forms of Association......Page 416 Understanding when You Should Use Parentheses......Page 417 Summary......Page 418 Choosing Your Course with Conditional Blocks......Page 419 Understanding the Basic Conditional Statement......Page 420 Offering an Alternative Ending with the else Clause......Page 421 Offering Multiple Choices with else if Clauses......Page 422 Tips for Writing Conditional Statements......Page 423 Running an Assembly Line with Repeat Loops......Page 424 The Different Flavors of Repeat Loops......Page 425 Repeating Forever......Page 426 Repeating with Numbers in a Range......Page 427 Repeating with Items in a List......Page 430 Repeating While/Until a Condition Is Met......Page 434 Tips for Writing Repeat Statements......Page 436 Summary......Page 440 Making Decisions When Dealing with Errors......Page 443 Unbalanced Parentheses and Unescaped Quotes......Page 444 Reserved Word Mishaps......Page 445 How Runtime Errors Work in AppleScript......Page 446 Understanding the Anatomy of an Error......Page 449 Trapping Runtime Errors......Page 450 Generating Runtime Errors......Page 455 Tips for Handling Runtime Errors......Page 458 Identifying Operating System Errors......Page 461 Identifying Apple Event Errors......Page 462 Identifying Application Scripting Errors......Page 463 Identifying AppleScript Language Errors......Page 464 Summary......Page 465 Introducing the display dialog Command......Page 467 Introducing the display alert Command......Page 477 Introducing the choose from list Command......Page 479 Introducing the choose file Command......Page 484 Introducing the choose file name Command......Page 490 Introducing the choose folder Command......Page 493 Introducing the choose application Command......Page 495 Introducing the choose remote application Command......Page 496 Introducing the choose URL Command......Page 497 Introducing the choose color Command......Page 498 Summary......Page 500 Identifying Files, Folders, and Disks......Page 501 Using Path Strings......Page 502 Using File System Objects......Page 504 File URL Strings......Page 512 Commands for Reading and Writing Files......Page 513 Dealing with Text File Encodings......Page 525 Summary......Page 532 What Are User-Defined Handlers?......Page 535 Creating a Simple Handler......Page 537 Using Parameters......Page 538 Using the return Statement......Page 539 Working with Return Values......Page 540 Can a Handler Return More Than One Result?......Page 541 Specifying Handler Parameters......Page 542 Using Positional Parameters......Page 543 Using Labeled Parameters......Page 545 Introducing Recursion......Page 549 I’ve Never Seen No run Handler!......Page 550 When Should You Make the run Handler Explicit?......Page 551 Using the Standard Event Handlers......Page 552 Organizing Code......Page 556 Thinking Small......Page 557 Reorganizing Existing Code......Page 558 Example Project: A Reusable Associative List......Page 559 Designing the Associative List......Page 560 Writing the Essential Handlers......Page 561 Writing the Extra Handlers......Page 564 Revising the Design......Page 565 Conclusion......Page 567 Summary......Page 568 Introducing Script Objects......Page 571 What Is a Script Library?......Page 572 Understanding Script Objects......Page 573 Defining a Script Object in a Script......Page 574 Loading and Storing Script Objects from Disk......Page 575 How Variable Scope Works in Script Objects......Page 576 Working with Script Libraries......Page 578 What Advantages Do Script Libraries Provide?......Page 579 Where Should You Save Your Library?......Page 580 What Are the Options for Loading Script Libraries?......Page 582 Beginning Object-Oriented Programming......Page 586 Your First Object: A Better Associative List......Page 587 Extending Objects Through Inheritance......Page 593 Creating Plug-and-Play Objects......Page 603 Summary......Page 613 Part 3: Putting AppleScript to Work......Page 615 How the Finder Represents the Mac OS X File System......Page 617 Understanding Containers......Page 619 Understanding Files......Page 622 Understanding the computer-object Class......Page 624 How System Events Represents the Mac OS X File System......Page 625 Understanding Files......Page 627 Understanding Folders......Page 628 Understanding System Events’ alias Class......Page 629 Other Classes of Interest......Page 630 Opening and Closing Items......Page 632 Duplicating Files and Folders......Page 633 Deleting Files and Folders......Page 634 Moving Files and Folders......Page 635 Making New Items......Page 636 Sorting Lists of Finder References......Page 637 Converting Finder References to AppleScript Aliases......Page 638 Filtering the Content of Folders......Page 640 Getting the Entire Contents of a Folder......Page 641 Locating Important Files and Folders with Standard Additions......Page 642 Avoiding Hardcoded Paths to the Startup Disk and Home Folder......Page 643 Getting the Path to the Currently Running Script......Page 644 Getting Paths to Resources in an Application Bundle......Page 646 Mounting Volumes......Page 648 Summary......Page 651 Scripting iTunes......Page 653 Understanding the iTunes Object Model......Page 654 Working with Sources......Page 656 Working with Tracks and Playlists......Page 657 Example Project: My Themed Playlist......Page 661 Scripting Mail......Page 665 Working with Messages......Page 666 Creating Outgoing Messages......Page 671 Working with Mail Rules......Page 672 Example Project: Building a Monthly Message Archive......Page 676 Scripting iCal......Page 680 Working with Calendars......Page 682 Working with Events......Page 683 Scripting Address Book......Page 685 Working with People......Page 686 Working with Groups......Page 689 Working with Rollovers......Page 691 Example Project: Looking Up Contact Information by Name......Page 693 Using the Run AppleScript Action......Page 696 Scripting the Automator Application......Page 701 Summary......Page 703 Introducing Scripting Additions and Scriptable Faceless Background Applications......Page 705 Scripting Additions and the AppleScript Language......Page 707 Installing Scripting Additions......Page 708 Missing Additions and Garbled Scripts......Page 709 Distributing Scripting Additions with Your Scripts......Page 710 Understanding Scripting Addition Compatibility Issues......Page 713 Distributing Scriptable FBAs with Your Scripts......Page 718 Third-Party Extensions......Page 719 Using the Standard Additions Scripting Addition......Page 720 Providing Audio Feedback......Page 721 Getting and Setting the System Volume......Page 722 Getting System Information......Page 723 Working with URLs......Page 724 Using the Image Events Faceless Background Application......Page 725 Processing Text with the Satimage Scripting Addition......Page 727 Performing Simple Find and Replace Tasks......Page 728 Counting Occurrences of a Substring in a String......Page 729 Finding and Replacing Substrings in a File......Page 730 Finding and Replacing Text with Regular Expressions......Page 731 Batch-Changing File Names......Page 737 Summary......Page 740 Using the Services Menu......Page 741 Creating Your Own Services......Page 742 Scheduling Scripts with iCal......Page 745 Triggering Scripts with Folder Actions......Page 746 Managing Your Folder Actions......Page 747 Creating Your First Folder Action......Page 749 Controlling Applications with GUI Scripting......Page 752 GUI Scripting Object Structure......Page 753 Basic GUI Scripting Examples......Page 755 Using GUI Scripting Commands......Page 756 Example Project: Searching in Preview......Page 758 Understanding the Limitations of GUI Scripting......Page 765 Getting Clipboard Data into AppleScript......Page 766 Setting the Clipboard Data......Page 767 Example Project: Creating PDF Cuttings from Selections in Preview......Page 769 Summary......Page 772 Scripting iWork......Page 773 Scripting Pages......Page 774 Scripting Keynote......Page 781 Scripting Numbers......Page 788 Scripting Microsoft Office......Page 790 Working with Microsoft Entourage......Page 791 Working with Excel......Page 807 Working with Word......Page 818 Where Next?......Page 821 Summary......Page 822 Scripting Data and Databases......Page 823 Automating FileMaker Pro with AppleScript......Page 824 The FileMaker Object Model and the Commands You Can Use......Page 825 Finding Data Quickly with the whose Clause......Page 832 Running AppleScripts from Inside FileMaker Pro......Page 836 Scripting Runtime Labs’ MacSQL......Page 837 Getting Connected......Page 838 More on Result Sets......Page 839 Some Useful Handlers......Page 840 Database Events Classes and Commands......Page 842 Database Events Examples......Page 843 Summary......Page 844 Scripting Adobe InDesign......Page 847 Learning by Example......Page 848 How InDesign Organizes Its Many Properties......Page 850 How InDesign Manages Units of Measurement......Page 853 How to Set Properties Safely when Making New Objects......Page 854 Working with Documents......Page 855 Working with Document Layers......Page 859 Working with Text......Page 861 Working with Text Stories......Page 862 Working with References to Text......Page 863 Working with Graphics......Page 865 Drawing Lines......Page 866 Example Project: An InDesign Scripts Launcher......Page 867 Working with Tables......Page 870 Importing Table Text from a Spreadsheet......Page 871 Copying Formatting Between Cells......Page 873 Working with Selections......Page 875 Example Project: Captioning a Selected Graphic......Page 876 Example Project: Cleaning Up Selected Text......Page 878 Labeling Objects for Use in Workflow Scripts......Page 880 Taking Advantage of AppleScript-Specific Preferences......Page 882 Example Project: Replacing Tags with Images......Page 884 Preparing InDesign......Page 885 Processing the Tags......Page 886 Preparing the Image Files......Page 887 Placing the Graphics......Page 888 Using InDesign on a Server......Page 890 Summary......Page 891 Why and When Are Shell Scripts Used in AppleScript?......Page 893 The Unix Command Line and Mac Desktop Compared......Page 894 How the Unix Command Line Works......Page 895 Getting Help......Page 899 Things to Watch Out For......Page 900 Some Useful Unix Commands......Page 902 Scripting the Terminal Application......Page 903 Using the do shell script Command......Page 905 Assembling Shell Script Strings......Page 909 Passing Data to Standard Input......Page 913 Using the osascript Command......Page 916 Passing Parameters to the Script......Page 917 Simple Text Processing Handlers......Page 918 Changing File System Permissions......Page 920 Analyzing PDF Files......Page 923 Summary......Page 926 Introducing Smile’s Integrated Engine Architecture......Page 927 Why Should You Use Smile?......Page 928 Using Smile......Page 929 Using the AppleScript Command-Line Environment......Page 930 Using Smile’s Custom Dialog Boxes......Page 931 Using Regular Expressions......Page 933 Using the Graphic Engine......Page 934 Using SmileLab......Page 935 Preparing the PDF......Page 938 Rolling Up the Scripts into a Graphical Interface......Page 945 Further Exercises......Page 955 Summary......Page 956 Tips and Techniques for Improving Your Scripts......Page 957 Taking Your Scripting Skills to the Next Level......Page 958 How Much Design Do Your Scripts Need?......Page 959 Starting Out Is Hard (But Gets Easier with Practice)......Page 961 How the Design-Driven Approach Changes the Way You Think About Code......Page 963 Testing and Debugging Your Code......Page 964 General Testing Tips and Techniques......Page 965 Debugging in AppleScript Editor......Page 968 Debugging in Script Debugger......Page 971 Keeping Track of Changes......Page 974 The Dos and Don’ts of Optimization......Page 978 Common AppleScript Optimizations......Page 981 Advanced Optimization Techniques......Page 986 Summary......Page 996 Creating Cocoa Applications with AppleScriptObjC......Page 999 Example Project: HelloAppleScriptObjC......Page 1000 Creating the Project in Xcode......Page 1001 Constructing the Interface in Interface Builder......Page 1003 Building and Testing the Application......Page 1009 Understanding Targets and Actions......Page 1010 How AppleScript Interacts with Cocoa Objects......Page 1012 What Is All That Code in the Default AppleScript File?......Page 1013 Creating the Project and Adding the Code......Page 1015 Constructing the Interface......Page 1016 Building and Testing the Application......Page 1017 Understanding How It Works......Page 1018 Viewing the Cocoa Documentation in Xcode......Page 1020 How Cocoa Classes Are Documented......Page 1021 How Cocoa Methods Are Documented......Page 1023 Constructing the Interface......Page 1026 Completing the Code......Page 1027 Understanding How It Works......Page 1029 Preparing the Text Fields Using an awakeFromNib Handler......Page 1030 Adjusting the Code for Bindings......Page 1031 Setting Up Bindings in Interface Builder......Page 1032 Adding the Sound File Resources to the Project......Page 1036 Building and Testing the Application......Page 1037 Understanding How It Works......Page 1038 Creating the Project and Starting the Code......Page 1039 Constructing the Interface......Page 1040 Completing the Code......Page 1043 Extra Exercises......Page 1045 Where Next?......Page 1046 Summary......Page 1047 Conclusion......Page 1048 ¦ A......Page 1049 ¦ B......Page 1055 ¦......Page 1056 ¦......Page 1062 ¦......Page 1065 ¦......Page 1067 ¦ G......Page 1071 ¦......Page 1072 ¦......Page 1073 ¦ K......Page 1076 ¦ M......Page 1078 ¦ N......Page 1081 ¦ O......Page 1082 ¦......Page 1084 ¦......Page 1087 ¦......Page 1090 ¦......Page 1096 ¦......Page 1099 ¦......Page 1101 ¦......Page 1102 ¦ Z......Page 1103
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
What you’ll learn - See how AppleScript represents information as objects—including numbers, strings, lists, and records.
- Learn how to manipulate these objects using commands and operators, and how to store them in variables.
- Organize your code using handlers and script objects.
- Understand how applications describe their objects and commands in dictionaries and how to interpret that information when learning to script applications.
- Manipulate the Mac OS X file system.
- Automate iTunes, Mail, iCal, and other popular lifestyle applications in Mac OS X.
- Discover sophisticated text processing techniques using regular expressions.
- Script professional productivity applications—Apple iWork, Microsoft Office, FileMaker Pro, and Adobe InDesign.
- Harness the power of the Unix command line in Mac OS X.
- Create your own Cocoa applications with the new AppleScriptObjC bridge.
Who this book is for - First-time scripters who want to automate tasks on their Macs
- Existing AppleScripters looking to develop proficient, professional, or guru-level knowledge and skills
- Professional Mac OS X developers wishing to understand this powerful and pervasive technology
Table of Contents
- Introducing AppleScript
- AppleScript in Principle
- AppleScript in Practice
- Writing Scripts in AppleScript Editor
- Understanding How Application Scripting Works
- Learning to Work with AppleScript Objects
- Working with Text
- Working with Numbers
- Working with Dates
- Working with Lists and Records
- Storing Objects in Variables
- More on Commands
- More on Operators and Coercions
- Making Decisions Using Conditionals and Loops
- Making Decisions When Dealing with Errors
- Interacting with the User
- Working with Files
- Organizing Your Code with Handlers
- Organizing Your Code with Script Objects
- Scripting the File System
- Scripting Apple Applications
- Extending AppleScript with Scripting Additions
- AppleScript Amenities
- Scripting iWork and Office
- Scripting Data and Databases
- Scripting Adobe InDesign
- Interacting with the Unix Command Line
- Using Smile: The AppleScript Integrated Production Environment
- Tips and Techniques for Improving Your Scripts
- Creating Cocoa Applications with AppleScriptObjC
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