Encyclopedia > AppleScript programming language

  Article Content

AppleScript

Redirected from AppleScript programming language

AppleScript is a scripting language devised by Apple Computer, and built into Mac OS. More generally, AppleScript is the word used to designate the Mac OS scripting interface, which is meant to operate in parallel with the graphical user interface.

Table of contents

History

The AppleScript project was an outgrowth of the HyperCard project. HyperCard had an English language based scripting language called HyperTalk which could be used for embedding logic and behavior into a HyperCard stack. Apple engineers recognized that a similar type of scripting language could be designed so as to be used with any application, and the AppleScript project was born.

The Natural Language Metaphor

In keeping with the Mac OS tradition of ease-of-use, the AppleScript language is designed on the natural language metaphor, just as the graphical user interface is designed on the desktop metaphor. Thus, the concept of an object hierarchy is expressed using nested prepositional phrases:

pixel 7 of row 3 of TIFF image "my bitmap"

which in another programming language might be expressed as sequential function calls:

getTIFF("my bitmap")->getRow(3)->getPixel(7)

Interapplication Communication

AppleScript was designed to be primarily used as a scripting language to control other applications. As such, it depends on the Mac OS interapplication communication protocol called AppleEvents. AppleEvents are essentially a byte-code representation of a message sent from one application to another. AppleScript uses an application dictionary to associate the bytecodes with human readable terminology, thus allowing the translation back and forth between human readable AppleScript and bytecode AppleEvents.

To designate which application is meant to be the target of such a message, AppleScript uses a 'tell' construct:

tell application "Microsoft Word" to quit

AppleScript on its Own

AppleScript need not depend on other applications. For very simple tasks, AppleScript can be used for self contained applets. For instance, the code:

set pix to 72
set answer to text returned of (display dialog "Enter in the number of inches" default answer "1")
display dialog answer & "in = " & (answer * pix) & "px"

Brings up a dialog box requesting a number of inches from the user. This number is then converted to pixles on a system that uses 72 pixles per inch. A second dialog box is brought up displaying the result.

AppleScript Studio

With Mac OS X/Cocoa , AppleScript has grown well beyond its humble beginnings. AppleScript Studio[?] is a development environment which is free with Mac OS X which uses AppleScript as the primary programming language, in conjunction with the Cocoa-based ProjectBuilder framework used to construct graphical user interfaces.

AppleScript Dialects

For a short time, AppleScript supported the idea of multiple dialects, which included English, French, Japanese, Japanese(romaji), and Italian. Terminology was made available for each dialect, such that the AppleScript compiler could compile and decompile scripts written in any dialect to any other dialect. While the project was a technical success, few application developers provided terminology in multiple languages, and technical support and testing proved to be far too much effort for the very little return on investment. Support for multiple dialects was dropped by Apple in Mac OS 8.5

AppleScript Language Essentials

  • basic data types are string, integer, real, list, record and object
    • different types can coexist in a list, including nested lists
    • records are lists of key-value pairs
  • standard control flow with if / else constructions and repeat loops
  • variables are instantiated when used, and are not strictly typed
  • script objects can encapsulate methods and data
  • script objects can inherit behavior from a parent script
  • 'tell' contruct used to identify target of message
  • applications can define terminology at runtime
  • runtime compiling possible using 'run script' construct
  • persistence possible using 'store script' and 'load script'

AppleScript External Links



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Rameses

... II ("The Great") Ramses III Ramses IV[?] The name means "Child of the Sun". This is a disambiguation page; that is, one that just points to other pages ...

 
 
 
This page was created in 501.5 ms