AppleEvents are one of the lesser-known, but pivotal features in making the MacOS
good. Basically, AppleEvents are messages that pass between any apps on the system. Any app can send an AppleEvent to any other app. An AppleEvent consists of a "header
", if you will, which is a 4-letter code. Some codes are reserved by the system or conventionally used for a very basic function
is the code for sending a "Document owned by this app has been launched" message). Some are invented by the application. Each AppleEvent has parameters; a text
parameter, a boolean
parameter, a file pointer
parameter, a Mac data
parameter, and so on. The sending app can fill any or all of these parameters with data it wishes to transmit. (The odoc
message must always be accompanied by a file
parameter, for example)
AppleScript is a user-level medium for directing applications via AppleEvents. It is basically just a frontend to the AppleEvent API. It saves the writer from having to deal with cryptic four letter codes, and allows them to use English-like terms and syntax. However, programmers also have access to this functionality. They must use the API directly to formulate their code, target, and attach their parameters.
AppleEvents are used for basic OS-level functions, too. For example, it is a convention for an application to, when text is dropped on one of its editfields, fill the field with the dropped text. To reiterate, ANY application can transmit text via drag and drop to ANY other application. Try that on Windows sometime.
A good analogy for this is that all the applications know a common language. Even if they've never met before, they can still communicate with one another, on account of knowing this common language. Take ircle, an IRC client with a very robust and well documented implementation of AppleEvents. It allows not only control via AppleEvents, but on the fly compilation of scripts. So, I can write a script to accept / commands on the input line, and use an AppleScript to subsequently control my MP3 player, like that. Or my email program. Or my web browser. Or AIM. Or... you get the idea.
There is, as far as I know, nothing as advanced or seamless as this on any other popular GUI OS.