Natural Language Metaphor
Whereas Apple Events are a way to send messages into applications, AppleScript is a particular language designed to send Apple Events. 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. A well-written AppleScript should be clear enough to be read and understood by anyone, and easily edited. The language is based largely on HyperCard's HyperTalk language, extended to refer not only to the HyperCard world of cards and stacks, but also theoretically to any document. To this end, the AppleScript team introduced the AppleEvent Object Model (AEOM), which specifies the objects any particular application "knows".
The heart of the AppleScript language is the use of terms that act as nouns and verbs that can be combined. For example, rather than a different verb to print a page, document or range of pages (printPage, printDocument, printRange) AppleScript uses a single "print" verb which can be combined with an object, such as a page, a document or a range of pages.
print page 1 print document 2 print pages 1 thru 5 of document 2Generally, AEOM defines a number of objects—like "document" or "paragraph"--and corresponding actions—like "cut" and "close". The system also defines ways to refer to properties of objects, so one can refer to the "third paragraph of the document 'Good Day'", or the "color of the last word of the front window". AEOM uses an application dictionary to associate the Apple Events with human-readable terms, allowing the translation back and forth between human-readable AppleScript and bytecode Apple Events. To discover what elements of a program are scriptable, dictionaries for supported applications may be viewed. (In the Xcode and Script Editor applications, this is under File → Open Dictionary.)
To designate which application is meant to be the target of such a message, AppleScript uses a "tell" construct:
tell application "Microsoft Word" quit end tellAlternatively, the tell may be expressed in one line by using an infinitive:
tell application "Microsoft Word" to quitFor events in the "Core Suite" (activate, open, reopen, close, print, and quit), the application may be supplied as the direct object to transitive commands:
quit application "Microsoft Word"The concept of an object hierarchy can be expressed using nested blocks:
tell application "QuarkXPress" tell document 1 tell page 2 tell text box 1 set word 5 to "Apple" end tell end tell end tell end tellThe concept of an object hierarchy can also be 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 method calls:
getTIFF("my bitmap").getPixel(3,7);AppleScript includes syntax for ordinal counting, "the first paragraph", as well as cardinal, "paragraph one". Likewise, the numbers themselves can be referred to as text or numerically, "five", "fifth" and "5" are all supported, they are called synonyms. Also, to add to the English-likeness, the word "the" can legally be used anywhere in the script in order to enhance readability: it has no effect on the functionality of the script.
Read more about this topic: AppleScript
Famous quotes containing the words natural, language and/or metaphor:
“No Vice or Wickedness, which People fall into from Indulgence to Desires which are natural to all, ought to place them below the Compassion of the virtuous Part of the World; which indeed often makes me a little apt to suspect the Sincerity of their Virtue, who are too warmly provoked at other Peoples personal Sins.”
—Richard Steele (16721729)
“To write or even speak English is not a science but an art. There are no reliable words.... Whoever writes English is involved in a struggle that never lets up even for a sentence. He is struggling against vagueness, against obscurity, against the lure of the decorative adjective, against the encroachment of Latin and Greek, and, above all, against the worn-out phrases and dead metaphors with which the language is cluttered up.”
—George Orwell (19031950)
“A good metaphor is something even the police should keep an eye on.”
—G.C. (Georg Christoph)