blob: b5fd4add04e4b191bdef1b03b2a347ce2f101c39 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`aetools` --- OSA client support
3=====================================
4
5.. module:: aetools
6 :platform: Mac
7 :synopsis: Basic support for sending Apple Events
8.. sectionauthor:: Jack Jansen <Jack.Jansen@cwi.nl>
9
10
11.. % \moduleauthor{Jack Jansen?}{email}
12
13The :mod:`aetools` module contains the basic functionality on which Python
14AppleScript client support is built. It also imports and re-exports the core
15functionality of the :mod:`aetypes` and :mod:`aepack` modules. The stub packages
16generated by :mod:`gensuitemodule` import the relevant portions of
17:mod:`aetools`, so usually you do not need to import it yourself. The exception
18to this is when you cannot use a generated suite package and need lower-level
19access to scripting.
20
21The :mod:`aetools` module itself uses the AppleEvent support provided by the
22:mod:`Carbon.AE` module. This has one drawback: you need access to the window
23manager, see section :ref:`osx-gui-scripts` for details. This restriction may be
24lifted in future releases.
25
26The :mod:`aetools` module defines the following functions:
27
28
29.. function:: packevent(ae, parameters, attributes)
30
31 Stores parameters and attributes in a pre-created ``Carbon.AE.AEDesc`` object.
32 ``parameters`` and ``attributes`` are dictionaries mapping 4-character OSA
33 parameter keys to Python objects. The objects are packed using
34 ``aepack.pack()``.
35
36
37.. function:: unpackevent(ae[, formodulename])
38
39 Recursively unpacks a ``Carbon.AE.AEDesc`` event to Python objects. The function
40 returns the parameter dictionary and the attribute dictionary. The
41 ``formodulename`` argument is used by generated stub packages to control where
42 AppleScript classes are looked up.
43
44
45.. function:: keysubst(arguments, keydict)
46
47 Converts a Python keyword argument dictionary ``arguments`` to the format
48 required by ``packevent`` by replacing the keys, which are Python identifiers,
49 by the four-character OSA keys according to the mapping specified in
50 ``keydict``. Used by the generated suite packages.
51
52
53.. function:: enumsubst(arguments, key, edict)
54
55 If the ``arguments`` dictionary contains an entry for ``key`` convert the value
56 for that entry according to dictionary ``edict``. This converts human-readable
57 Python enumeration names to the OSA 4-character codes. Used by the generated
58 suite packages.
59
60The :mod:`aetools` module defines the following class:
61
62
63.. class:: TalkTo([signature=None, start=0, timeout=0])
64
65 Base class for the proxy used to talk to an application. ``signature`` overrides
66 the class attribute ``_signature`` (which is usually set by subclasses) and is
67 the 4-char creator code defining the application to talk to. ``start`` can be
68 set to true to enable running the application on class instantiation.
69 ``timeout`` can be specified to change the default timeout used while waiting
70 for an AppleEvent reply.
71
72
73.. method:: TalkTo._start()
74
75 Test whether the application is running, and attempt to start it if not.
76
77
78.. method:: TalkTo.send(code, subcode[, parameters, attributes])
79
80 Create the AppleEvent ``Carbon.AE.AEDesc`` for the verb with the OSA designation
81 ``code, subcode`` (which are the usual 4-character strings), pack the
82 ``parameters`` and ``attributes`` into it, send it to the target application,
83 wait for the reply, unpack the reply with ``unpackevent`` and return the reply
84 appleevent, the unpacked return values as a dictionary and the return
85 attributes.
86