Posted  by  admin

Applescript: Applescript For Mac

  1. Applescript: Applescript For Mac Mac

The following online materials are exerpted from the Apple Training Series book. The First Step Consider this chapter a “book within a book.” If you don't read any other chapter, read this one. It has been designed to give you a quick but thorough introduction to AppleScript through a short, fun, hands-on tutorial. In 25 minutes you’ll learn what AppleScript is, how it works, and how to write basic, functional AppleScript scripts with confidence. To accomplish this goal, you’ll learn the fundamentals of AppleScript, and then put them to use as we step through the creation of a Finder Toolbar script, that you can use to instantly reset a cluttered desktop window display to a predefined window set. What is AppleScript? AppleScript is a language used to automate the actions of the Macintosh Operating System and many of its applications.

Whether a task is as simple as copying a file or as complex as building a real estate catalog, AppleScript can perform the requisite actions for you with “intelligence,” controlling applications and making decisions based on its observations or from information provided by its interaction with the person running the script. Every day, businesses and individuals alike use AppleScript to create newspapers and books, manage networks, build DVDs, process images, generate web pages, backup files and folders, make videos, and much more. AppleScript is the most powerful, easy-to-use, automation tool available on any platform. And best of all, this technology is free and is built into every copy of the Mac OS!

How it works. To automate the actions of applications, the computer reads the sequential instructions contained in AppleScript “scripts,” and then communicates those instructions to targeted applications. The targeted applications interpret the communicated instructions, and then perform the actions listed in the scripts. AppleScript scripts are composed, by motivated users like yourself, in AppleScript, an English-like language containing many of the verbs, nouns, adjectives, articles and other English language elements we use every day.

Mac

The AppleScript language is designed to be easily understandable, and has a syntax or grammatical structure similar to the one we use to create normal sentences. Scripts are written in the Script Editor application, a free utility included with every copy of the Mac OS. Scripts can be “run” from within the Script Editor application or saved as either script files or script applications, available for use at any time, and from within any application. Script files are launched from an application’s script menu or from the Mac OS system-wide Script Menu utility. Script applications, or “applets,” are launched like other applications by double-clicking their icons in the Finder or by clicking their Dock or Finder Toolbar and Sidebar icons.

The Big Picture AppleScript is based on the concept of scriptable objects belonging to or being contained in other scriptable objects, such as a file being in a folder that belongs to the hard disk, or a word being part of a paragraph belonging to a story. Understanding the relationship between scriptable objects is essential to learning how to write scripts, and can be summarized in the following statements: On the Macintosh computer everything is an object. The computer, the desktop, the disks it displays, the folders on the disks and the files in those folders — all of these items are objects. So are applications, their documents, and the data in those documents.

Everything belongs to, is related to, is contained in, or is part of something else. The file is in the folder that is in the disk that is on the desktop that is on the computer. This same relationship can apply to text as well. The character is in the word that is in the line that is part of the paragraph that is contained in the story. This relationship between objects is referred to as being hierarchical or, in military terms, follows a “Chain of Command.” AppleScript uses this hierarchical containment structure to identify specific scriptable objects. Silent hunter 4 sold for mac. All the scripts you write will contain hierarchical references.

Just remember this: In scripts, objects are described in terms of their position in their hierarchical structure, or where they are in their “Chain of Command.” NOTE: Don’t be put off by the term hierarchical. We often use hierarchical references to identify objects in our lives.

For example, you refer to your home as being on a specific street, in a specific city, in a specific county, in a specific state, in a specific country. Or your advanced pottery class as being in room 128, on the third floor, of the west wing, of the Creative Arts building. Object references in AppleScript work the same way.

Important: This document is no longer being updated. For the latest information about Apple SDKs, visit the. This document is a guide to the AppleScript language—its lexical conventions, syntax, keywords, and other elements. It is intended primarily for use with AppleScript 2.0 or later and macOS version 10.5 or later. AppleScript 2.0 can use scripts developed for any version of AppleScript from 1.1 through 1.10.7, any scripting addition created for AppleScript 1.5 or later for macOS, and any scriptable application for Mac OS v7.1 or later.

A script created with AppleScript 2.0 can be used by any version of AppleScript back to version 1.1, provided it does not use features of AppleScript, scripting additions, or scriptable applications that are unavailable in that version. Important: Descriptions and examples for the terms in this document have been tested with AppleScript 2.0 in OS X v10.5 (Leopard). Except for terms that are noted as being new in Leopard, most descriptions and examples work with previous system versions, but have not been tested against all of them.

If you need detailed information about prior system and AppleScript versions, see AppleScript Release Notes (OS X v10.4 and earlier). What Is AppleScript? AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself.

You can create scripts—sets of written instructions—to automate repetitive tasks, combine features from multiple scriptable applications, and create complex workflows. Note: Apple also provides the Automator application, which allows users to automate common tasks by hooking together ready-made actions in a graphical environment. For more information, see.

A scriptable application is one that can be controlled by a script. For AppleScript, that means being responsive to interapplication messages, called Apple events, sent when a script command targets the application. (Apple events can also be sent directly from other applications and macOS.) AppleScript itself provides a very small number of commands, but it provides a framework into which you can plug many task-specific commands—those provided by scriptable applications and scriptable parts of macOS. Most script samples and script fragments in this guide use scriptable features of the Finder application, scriptable parts of macOS, or scriptable applications distributed with macOS, such as TextEdit (located in /Applications). Who Should Read This Document?

You should use this document if you write or modify AppleScript scripts, or if you create scriptable applications and need to know how scripts should work. AppleScript Language Guide assumes you are familiar with the high-level information about AppleScript found in.

Organization of This Document This guide describes the AppleScript language in a series of chapters and appendixes. The first five chapters introduce components of the language and basic concepts for using it, then provide additional overview on working with script objects and handler routines:. describes the characters, symbols, keywords, and other language elements that make up statements in an AppleScript script. describes basic concepts that underly the terminology and rules covered in the rest of this guide.

describes common issues in working with variables and properties, including how to declare them and how AppleScript interprets their scope. describes how to define, initialize, send commands to, and use inheritance with script objects. provides information on using handlers (a type of function available in AppleScript) to factor and reuse code. The following chapters provide reference for the AppleScript Language:. describes the classes AppleScript defines for common objects used in scripts.

describes the commands that are available to any script. describes the syntax for specifying an object or group of objects in an application or other container. provides a list of the operators AppleScript supports and the rules for using them, along with sections that provide additional detail for commonly used operators. describes statements that control when and how other statements are executed. It covers standard conditional statements, as well as statements used in error handling and other operations. shows the syntax for defining and calling handlers and describes other statements you use with handlers.

The following chapter describes an AppleScript-related feature of macOS:. describes how you can write and attach script handlers to specific folders, such that the handlers are invoked when the folders are modified. The following appendixes provide additional information about the AppleScript language and how to work with errors in scripts:. lists the keywords of the AppleScript language, provides a brief description for each, and points to related information. describes error numbers and error messages you may see in working with AppleScript scripts.

provides detailed examples of handling errors with. describes when you are likely to see double angle brackets (or chevrons— «») in scripts and how you can work with them.

describes how to save libraries of handlers and access them from other scripts. lists terms that are no longer supported in AppleScript. Conventions Used in This Guide Glossary terms are shown in boldface where they are defined. Language element Plain computer font indicates an element that you type exactly as shown. If there are special symbols (for example, + or &), you also type them exactly as shown. Placeholder Italic text indicates a placeholder that you replace with an appropriate value.

Mac

optional Brackets indicate that the enclosed language element or elements are optional. (a group) Parentheses group elements together. However, the parentheses shown in are part of the syntax. Three ellipsis points (.) after a group defined by brackets indicate that you can repeat the group of elements within brackets 0 or more times. A b c Vertical bars separate elements in a group from which you must choose a single element. The elements are often grouped within parentheses or brackets. Filenames shown in scripts Most filenames shown in examples in this document include extensions, such as rtf for a TextEdit document.

Use of extensions in scripts is generally dependent on the “Show all file extensions” setting in the Advanced pane of Finder Preferences. To work with the examples on your computer, you may need to modify either that setting or the filenames. See Also These Apple documents provide additional information for working with AppleScript:.

See Getting Started with AppleScript for a guided quick start, useful to both scripters and developers. See, including the chapter, for a high-level overview of AppleScript and its related technologies.

Applescript: Applescript For Mac

See Getting Started With Scripting & Automation for information on the universe of scripting technologies available in macOS. See for a list of many of the scripting terms defined by Apple.

Applescript: Applescript For Mac Mac

For additional information on working with the AppleScript language and creating scripts, see one of the comprehensive third-party documents available in bookstores and online.