3.2 aetools -- OSA client support
Availability: Macintosh.
The aetools module contains the basic functionality on which Python AppleScript client support is built. It also imports and re-exports the core functionality of the aetypes and aepack modules. The stub packages generated by gensuitemodule import the relevant portions of aetools, so usually you do not need to import it yourself. The exception to this is when you cannot use a generated suite package and need lower-level access to scripting.
The aetools module itself uses the AppleEvent support provided by the Carbon.AE module. This has one drawback: you need access to the window manager, see section 1.1.2 for details. This restriction may be lifted in future releases.
The aetools module defines the following functions:
-
Stores parameters and attributes in a pre-created
Carbon.AE.AEDesc
object.parameters
andattributes
are dictionaries mapping 4-character OSA parameter keys to Python objects. The objects are packed usingaepack.pack()
.
-
Recursively unpacks a
Carbon.AE.AEDesc
event to Python objects. The function returns the parameter dictionary and the attribute dictionary. Theformodulename
argument is used by generated stub packages to control where AppleScript classes are looked up.
-
Converts a Python keyword argument dictionary
arguments
to the format required bypackevent
by replacing the keys, which are Python identifiers, by the four-character OSA keys according to the mapping specified inkeydict
. Used by the generated suite packages.
-
If the
arguments
dictionary contains an entry forkey
convert the value for that entry according to dictionaryedict
. This converts human-readable Python enumeration names to the OSA 4-character codes. Used by the generated suite packages.
The aetools module defines the following class:
-
Base class for the proxy used to talk to an application.
signature
overrides the class attribute_signature
(which is usually set by subclasses) and is the 4-char creator code defining the application to talk to.start
can be set to true to enable running the application on class instantiation.timeout
can be specified to change the default timeout used while waiting for an AppleEvent reply.
- Test whether the application is running, and attempt to start it if not.
-
Create the AppleEvent
Carbon.AE.AEDesc
for the verb with the OSA designationcode, subcode
(which are the usual 4-character strings), pack theparameters
andattributes
into it, send it to the target application, wait for the reply, unpack the reply withunpackevent
and return the reply appleevent, the unpacked return values as a dictionary and the return attributes.