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