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