AppleScript - Basic Concepts

Basic Concepts

AppleScript was designed to be used as an accessible end-user scripting language, offering users an intelligent mechanism to control applications, and to access and modify data and documents. AppleScript can be used to create automated workflows which can reduce the time and repetitiveness of various tasks, minimize the opportunity for human error, provide consistent output, and facilitate a manageable production system. AppleScript uses Apple Events: a set of standardized data formats that the Macintosh operating system uses to send information to applications. Apple Events allow a script to work with multiple applications simultaneously, passing data between them so that complex tasks can be accomplished without human interaction. For example, an AppleScript to create a simple web gallery might do the following:

  1. Open a photo in a photo-editing application (by sending that application an Open File Apple Event).
  2. Tell the photo-editing application to manipulate the image (e.g. reduce its resolution, add a border, add a photo credit)
  3. Tell the photo-editing application to save the changed image in a file in some different folder (by sending that application an Save and/or Close Apple Events).
  4. Send the new file path (via another Apple Event) to a text editor or web editor application
  5. Tell that editor application to write a link for the photo into an HTML file.
  6. Repeat the above steps for an entire folder of images (hundreds or even thousands of photos).
  7. Upload the HTML file and folder of revised photos to a website, by sending Apple Events to an FTP client, by using built-in AppleScript commands, or by sending Apple Events to Unix ftp utilities.

For the user, hundreds or thousands of steps in multiple applications have been reduced to the single act of running the script, and the task is accomplished in much less time and with no possibility of random human error. A large complex script could be developed to run only once, while other scripts are used again and again.

An application's AppleScript elements are visible in the application's Scripting Dictionary (distributed as part of the application), which can be viewed in any script editor. Elements are generally grouped into suites, according to loose functional relationships between them. There are two basic kinds of elements present in any suite: Classes and Commands. Classes are scriptable objects - for example, a text editing application will almost certainly have classes for Windows, Documents, and Texts - and these classes will have properties that can be changed (window size, document background color, text font size, etc.), and may contain other classes (a window will contain one or more documents, a document will contain text, a text object will contain paragraphs and words and characters). Commands, by contrast, are commands that can be given to scriptable objects. The general format for a block of AppleScript is to tell a scriptable object to run a command.

All scriptable applications share a few basic commands and objects (usually called the Standard Suite) - commands to open, close or save a file, to print something, to quit, to set data to variables - as well as a basic application object that gives the scriptable properties of the application itself. Many applications have numerous suites capable of performing any task the application itself can perform. In exceptional cases, applications may support plugins which include their own scripting dictionaries.

AppleScript was designed with the ability to build scripts intuitively by recording user actions. When the AppleScript Editor is open and the Record button clicked, any user actions on the computer - in any application that supports AppleEvents and AppleScript recording - are converted to their equivalent AppleScript commands and placed in the script editor window. The resulting script can be saved and re-run to duplicate the original actions, or modified to be more generally useful.

Read more about this topic:  AppleScript

Famous quotes containing the words basic and/or concepts:

    The basic tool for the manipulation of reality is the manipulation of words. If you can control the meaning of words, you can control the people who must use the words.
    Philip K. Dick (1928–1982)

    Germany collapsed as a result of having engaged in a struggle for empire with the concepts of provincial politics.
    Albert Camus (1913–1960)