Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
AppleScript
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== 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 objective of ease-of-use for beginners, the AppleScript language is designed on the [[natural language programming|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 (such as 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. <syntaxhighlight lang="AppleScript"> print page 1 print document 2 print pages 1 thru 5 of document 2 </syntaxhighlight> Generally, 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 [[AppleScript Editor|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: <syntaxhighlight lang="AppleScript"> tell application "Microsoft Word" quit end tell </syntaxhighlight> Alternatively, the tell may be expressed in one line by using an [[infinitive]]: <syntaxhighlight lang="AppleScript"> tell application "Microsoft Word" to quit </syntaxhighlight> For events in the "Core Suite" (activate, open, reopen, close, print, and quit), the application may be supplied as the [[Object (computer science)|direct object]] to transitive commands: <syntaxhighlight lang="AppleScript"> quit application "Microsoft Word" </syntaxhighlight> The concept of an object [[hierarchy]] can be expressed using nested blocks: <syntaxhighlight lang="AppleScript"> 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 tell </syntaxhighlight> The concept of an object [[hierarchy]] can also be expressed using either nested [[prepositional phrase]]s or a series of possessives: <syntaxhighlight lang="AppleScript"> pixel 7 of row 3 of TIFF image "my bitmap" TIFF image "my bitmap"'s 3rd row's 7th pixel </syntaxhighlight> which in another [[programming language]] might be expressed as sequential [[subroutine|method calls]], like in this [[pseudocode]]: <syntaxhighlight lang="JavaScript"> getTIFF("my bitmap").getRow(3).getPixel(7); </syntaxhighlight> 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 synonyms in AppleScript. Also, 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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
AppleScript
(section)
Add topic