<s>
Apple	B-Operating_System
events	I-Operating_System
are	O
the	O
message-based	O
interprocess	B-Operating_System
communication	I-Operating_System
mechanism	O
in	O
Mac	B-Application
OS	I-Application
,	O
first	O
making	O
an	O
appearance	O
in	O
System	B-Operating_System
7	I-Operating_System
and	O
supported	O
by	O
every	O
version	O
of	O
the	O
classic	B-Application
Mac	I-Application
OS	I-Application
since	O
then	O
and	O
by	O
macOS	B-Application
.	O
</s>
<s>
Apple	B-Operating_System
events	I-Operating_System
describe	O
"	O
high-level	O
"	O
events	O
such	O
as	O
"	O
open	O
document	O
"	O
or	O
"	O
print	O
file	O
"	O
,	O
whereas	O
earlier	O
OSs	O
had	O
supported	O
much	O
more	O
basic	O
events	O
,	O
namely	O
"	O
click	O
"	O
and	O
"	O
keypress	O
"	O
.	O
</s>
<s>
Apple	B-Operating_System
events	I-Operating_System
form	O
the	O
basis	O
of	O
the	O
Mac	B-Application
OS	I-Application
scripting	O
system	O
,	O
the	O
Open	O
Scripting	O
Architecture	O
(	O
the	O
primary	O
language	O
of	O
such	O
being	O
AppleScript	B-Application
)	O
.	O
</s>
<s>
The	O
starting	O
point	O
is	O
a	O
dynamically-typed	O
,	O
extensible	O
descriptor	O
format	O
called	O
an	O
AEDesc	O
,	O
which	O
is	O
just	O
an	O
OSType	B-Application
code	O
specifying	O
the	O
data	O
type	O
,	O
together	O
with	O
a	O
block	O
of	O
type-dependent	O
data	O
.	O
</s>
<s>
For	O
instance	O
,	O
the	O
OSType	B-Application
code	O
inte	O
indicates	O
that	O
the	O
data	O
was	O
a	O
four-byte	O
signed	O
integer	O
in	O
big-endian	O
format	O
.	O
</s>
<s>
Besides	O
predefined	O
type	O
codes	O
for	O
various	O
common	O
simple	O
types	O
,	O
there	O
are	O
two	O
predefined	O
structured	O
descriptor	O
types	O
:	O
an	O
AERecord	B-Operating_System
,	O
which	O
has	O
data	O
type	O
reco	O
(	O
record	O
)	O
,	O
and	O
AEList	O
with	O
type	O
list	O
(	O
list	O
or	O
array	O
)	O
.	O
</s>
<s>
The	O
internal	O
structure	O
of	O
these	O
contain	O
recursively-nested	O
AEDescs	O
,	O
while	O
the	O
AERecord	B-Operating_System
also	O
associates	O
each	O
element	O
with	O
a	O
unique	O
record	O
field	O
ID	O
,	O
which	O
is	O
an	O
OSType	B-Application
.	O
</s>
<s>
The	O
Apple	B-Operating_System
Event	I-Operating_System
Manager	O
provides	O
API	B-Application
calls	O
to	O
construct	O
these	O
structures	O
,	O
as	O
well	O
as	O
extract	O
their	O
contents	O
and	O
query	O
the	O
type	O
of	O
contents	O
they	O
hold	O
.	O
</s>
<s>
The	O
Apple	B-Operating_System
Event	I-Operating_System
Manager	O
also	O
supports	O
coercions	O
,	O
which	O
converts	O
AEDescs	O
from	O
one	O
data	O
type	O
to	O
another	O
.	O
</s>
<s>
An	O
Apple	B-Operating_System
event	I-Operating_System
proper	O
is	O
an	O
AERecord	B-Operating_System
with	O
fields	O
that	O
depended	O
on	O
the	O
purpose	O
of	O
the	O
event	O
.	O
</s>
<s>
In	O
addition	O
,	O
it	O
has	O
attributes	O
(	O
which	O
are	O
distinct	O
from	O
record	O
fields	O
,	O
which	O
are	O
now	O
called	O
the	O
parameters	O
of	O
the	O
event	O
)	O
from	O
a	O
set	O
predefined	O
by	O
the	O
Apple	B-Operating_System
Event	I-Operating_System
Manager	O
.	O
</s>
<s>
Remote	O
machines	O
initially	O
had	O
to	O
be	O
connected	O
via	O
AppleTalk	B-Application
,	O
but	O
Mac	B-Operating_System
OS	I-Operating_System
9	I-Operating_System
added	O
the	O
option	O
for	O
connections	O
via	O
TCP/IP	B-Protocol
.	O
</s>
<s>
After	O
sending	O
an	O
Apple	B-Operating_System
event	I-Operating_System
to	O
its	O
target	O
process	O
,	O
the	O
sending	O
process	O
can	O
elect	O
to	O
receive	O
a	O
reply	O
to	O
an	O
Apple	B-Operating_System
event	I-Operating_System
.	O
</s>
<s>
Apple	B-Operating_System
events	I-Operating_System
are	O
the	O
foundation	O
of	O
the	O
AppleEvent	B-Operating_System
Object	I-Operating_System
Model	I-Operating_System
,	O
which	O
in	O
turn	O
is	O
the	O
foundation	O
of	O
the	O
OSA	O
and	O
AppleScript	B-Application
.	O
</s>
<s>
,	O
the	O
official	O
implementation	O
of	O
the	O
Apple	B-Operating_System
Event	I-Operating_System
Manager	O
API	B-Application
is	O
available	O
in	O
C	B-Language
and	O
its	O
descendants	O
,	O
including	O
C++	B-Language
.	O
</s>
<s>
Official	O
bindings	O
are	O
also	O
provided	O
for	O
Objective-C	B-Language
and	O
Swift	B-Application
through	O
the	O
Cocoa	B-Operating_System
API	I-Operating_System
.	O
</s>
<s>
Unofficial	O
bindings	O
also	O
exist	O
for	O
other	O
languages	O
(	O
with	O
varying	O
degrees	O
of	O
limitation	O
)	O
,	O
including	O
Perl	B-Language
,	O
UserTalk	O
,	O
Ruby	B-Language
and	O
Python	B-Language
.	O
</s>
<s>
The	O
AppleEvent	B-Operating_System
Object	I-Operating_System
Model	I-Operating_System
(	O
AEOM	O
)	O
was	O
a	O
set	O
of	O
protocols	O
built	O
on	O
top	O
of	O
AppleEvents	B-Operating_System
by	O
which	O
applications	O
running	O
under	O
classic	B-Application
Mac	I-Application
OS	I-Application
and	O
macOS	B-Application
could	O
control	O
each	O
other	O
's	O
functions	O
.	O
</s>
<s>
Applications	O
that	O
implemented	O
some	O
part	O
of	O
the	O
AEOM	O
were	O
called	O
scriptable	O
because	O
they	O
could	O
be	O
controlled	O
via	O
AppleScript	B-Application
.	O
</s>
<s>
Unfortunately	O
,	O
scriptability	O
support	O
remained	O
patchy	O
and	O
inconsistent	O
throughout	O
the	O
history	O
of	O
classic	B-Application
Mac	I-Application
OS	I-Application
.	O
</s>
<s>
Unlike	O
other	O
similar-sounding	O
concepts	O
such	O
as	O
ToolTalk	B-Operating_System
,	O
there	O
was	O
a	O
clear	O
,	O
orthogonal	O
distinction	O
between	O
nouns	O
and	O
verbs	O
;	O
thus	O
,	O
instead	O
of	O
providing	O
separate	O
commands	O
for	O
"	O
close	O
document	O
"	O
and	O
"	O
close	O
window	O
"	O
,	O
there	O
was	O
a	O
single	O
"	O
close	O
"	O
verb	O
which	O
could	O
take	O
references	O
to	O
"	O
document	O
"	O
or	O
"	O
window	O
"	O
objects	O
,	O
or	O
any	O
other	O
object	O
that	O
the	O
application	O
published	O
.	O
</s>
<s>
Other	O
objects	O
were	O
referenced	O
by	O
(	O
recursively	O
)	O
specifying	O
their	O
parent	O
object	O
,	O
together	O
with	O
other	O
information	O
identifying	O
it	O
as	O
a	O
child	O
of	O
that	O
parent	O
,	O
all	O
collected	O
in	O
an	O
AERecord	B-Operating_System
.	O
</s>
<s>
The	O
system	O
was	O
generally	O
similar	O
to	O
the	O
Document	B-General_Concept
Object	I-General_Concept
Model	I-General_Concept
used	O
in	O
XML	B-Protocol
,	O
although	O
with	O
some	O
differences	O
in	O
access	O
patterns	O
.	O
</s>
<s>
Each	O
verb	O
was	O
defined	O
as	O
an	O
AppleEvent	B-Operating_System
of	O
a	O
specific	O
type	O
and	O
class	O
,	O
together	O
with	O
particular	O
parameters	O
of	O
particular	O
types	O
that	O
were	O
expected	O
to	O
be	O
present	O
.	O
</s>
<s>
The	O
entire	O
AppleEvent	B-Operating_System
architecture	O
identifies	O
things	O
using	O
four-byte	O
OSType	B-Application
codes	O
,	O
studiously	O
avoiding	O
actual	O
words	O
or	O
phrases	O
in	O
English	O
(	O
or	O
any	O
other	O
language	O
)	O
.	O
</s>
<s>
Instead	O
,	O
the	O
correspondence	O
between	O
internal	O
AppleEvent	B-Operating_System
codes	O
and	O
external	O
natural-language	O
descriptions	O
is	O
specified	O
through	O
the	O
aete	O
(	O
AppleEvent	B-Operating_System
Terminology	O
Extension	O
)	O
resource	B-Operating_System
the	O
"	O
extension	O
"	O
being	O
to	O
the	O
standard	O
terminology	O
built	O
into	O
AppleScript	B-Application
itself	O
.	O
</s>
<s>
For	O
instance	O
,	O
consider	O
the	O
following	O
AppleScript	B-Application
sequence	O
controlling	O
a	O
fictional	O
drawing	O
application	O
:	O
</s>
<s>
This	O
actually	O
involves	O
the	O
sending	O
of	O
two	O
AppleEvents	B-Operating_System
to	O
the	O
target	O
application	O
(	O
and	O
the	O
receipt	O
of	O
their	O
corresponding	O
replies	O
)	O
:	O
first	O
,	O
a	O
get-data	O
event	O
is	O
sent	O
to	O
retrieve	O
the	O
background	O
color	O
property	O
of	O
the	O
window	O
identified	O
by	O
the	O
name	O
"	O
Old	O
Drawing	O
"	O
;	O
then	O
a	O
set-data	O
event	O
is	O
sent	O
to	O
apply	O
the	O
value	O
returned	O
as	O
the	O
background	O
color	O
property	O
of	O
the	O
window	O
named	O
"	O
New	O
Drawing	O
"	O
.	O
</s>
<s>
Since	O
this	O
sort	O
of	O
access	O
pattern	O
was	O
typical	O
,	O
AppleScript	B-Application
made	O
widespread	O
use	O
of	O
the	O
tell	O
statement	O
,	O
which	O
switched	O
the	O
context	O
to	O
the	O
named	O
object	O
in	O
a	O
fashion	O
similar	O
to	O
the	O
with	O
statement	O
found	O
in	O
Visual	B-Language
Basic	I-Language
or	O
Pascal	B-Application
.	O
</s>
<s>
The	O
most	O
interesting	O
one	O
was	O
using	O
a	O
where-clause	O
(	O
which	O
translated	O
into	O
AppleScript	B-Application
terminology	O
as	O
a	O
filter	O
expression	O
)	O
.	O
</s>
<s>
For	O
instance	O
,	O
the	O
AppleScript	B-Application
1.0	O
SDK	B-Application
shipped	O
with	O
the	O
source	O
code	O
for	O
an	O
example	O
application	O
called	O
the	O
Scriptable	O
Text	O
Editor	O
,	O
which	O
would	O
respond	O
to	O
scripts	O
such	O
as	O
:	O
</s>
<s>
Even	O
today	O
,	O
it	O
is	O
rare	O
to	O
find	O
this	O
kind	O
of	O
power	O
in	O
general-purpose	O
scripting	O
languages	O
outside	O
of	O
SQL	B-Language
.	O
</s>
<s>
Adding	O
support	O
for	O
the	O
AEOM	O
in	O
the	O
classic	B-Application
Mac	I-Application
OS	I-Application
was	O
a	O
difficult	O
process	O
.	O
</s>
<s>
This	O
typically	O
took	O
the	O
form	O
of	O
code	O
for	O
returning	O
the	O
"	O
next	O
"	O
object	O
of	O
a	O
particular	O
type	O
,	O
allowing	O
AppleScript	B-Application
to	O
iterate	O
over	O
them	O
.	O
</s>
<s>
Oddly	O
,	O
even	O
Apple	O
's	O
own	O
application	B-Application
framework	I-Application
,	O
MacApp	B-Operating_System
,	O
did	O
not	O
offer	O
such	O
a	O
model	O
except	O
for	O
the	O
GUI	B-Application
objects	O
it	O
knew	O
about	O
,	O
once	O
again	O
making	O
the	O
developer	O
do	O
most	O
of	O
the	O
work	O
of	O
scripting	O
the	O
objects	O
representing	O
the	O
data	O
itself	O
.	O
</s>
<s>
Largely	O
for	O
these	O
reasons	O
,	O
AppleScript	B-Application
support	O
was	O
not	O
very	O
widespread	O
.	O
</s>
<s>
Applications	O
developed	O
in	O
Cocoa	B-Operating_System
,	O
the	O
system	O
formerly	O
known	O
as	O
OpenStep	B-Operating_System
,	O
offer	O
a	O
rich	O
object	O
runtime	O
that	O
can	O
be	O
queried	O
from	O
any	O
other	O
application	O
.	O
</s>
<s>
Additionally	O
the	O
majority	O
of	O
Cocoa	B-Operating_System
applications	O
are	O
constructed	O
primarily	O
from	O
Cocoa-standard	O
objects	O
,	O
all	O
of	O
which	O
were	O
upgraded	O
to	O
offer	O
fairly	O
extensive	O
scriptability	O
.	O
</s>
<s>
This	O
extends	O
not	O
only	O
to	O
GUI	B-Application
objects	O
as	O
under	O
MacApp	B-Operating_System
,	O
but	O
also	O
to	O
data	O
objects	O
inside	O
them	O
,	O
including	O
text	O
,	O
tables	O
and	O
various	O
list	O
objects	O
.	O
</s>
<s>
A	O
text	O
file	O
is	O
used	O
to	O
map	O
the	O
internal	O
"	O
object-like	O
"	O
names	O
onto	O
human-readable	B-General_Concept
versions	O
,	O
and	O
in	O
most	O
cases	O
creating	O
this	O
is	O
all	O
that	O
is	O
needed	O
to	O
add	O
fairly	O
substantial	O
scriptability	O
to	O
most	O
programs	O
.	O
</s>
<s>
While	O
Cocoa	B-Operating_System
applications	O
are	O
not	O
AEOM	O
based	O
,	O
and	O
often	O
use	O
subtly	O
different	O
objects	O
than	O
Apple	O
's	O
originally	O
defined	O
standard	O
objects	O
,	O
Cocoa	B-Operating_System
apps	O
are	O
generally	O
much	O
more	O
scriptable	O
than	O
their	O
"	O
classic	O
"	O
counterparts	O
—	O
in	O
fact	O
,	O
it	O
is	O
uncommon	O
to	O
find	O
a	O
Cocoa	B-Operating_System
application	O
that	O
is	O
not	O
scriptable	O
to	O
some	O
degree	O
.	O
</s>
<s>
The	O
Scripting	B-Application
Bridge	I-Application
is	O
a	O
macOS	B-Application
framework	O
which	O
allows	O
applications	O
to	O
communicate	O
with	O
each	O
other	O
without	O
the	O
use	O
of	O
an	O
intermediary	O
scripting	O
language	O
such	O
as	O
AppleScript	B-Application
.	O
</s>
<s>
Like	O
AppleScript	B-Application
,	O
the	O
Scripting	B-Application
Bridge	I-Application
uses	O
Apple	B-Operating_System
events	I-Operating_System
for	O
inter-application	B-Operating_System
communication	I-Operating_System
.	O
</s>
<s>
The	O
Scripting	B-Application
Bridge	I-Application
is	O
typically	O
used	O
from	O
Objective-C	B-Language
,	O
but	O
can	O
be	O
used	O
in	O
other	O
programming	O
languages	O
through	O
an	O
Objective-C	B-Language
bridge	O
such	O
as	O
MacRuby	B-Operating_System
and	O
PyObjC	B-Operating_System
.	O
</s>
