~dkuhlman/python-training-materials/Materials

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>38.2. aetools — OSA client support &mdash; Python 2.7.12 documentation</title>
    
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.7.12',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.12 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 2.7.12 documentation" href="../contents.html" />
    <link rel="up" title="38. MacPython OSA Modules" href="macosa.html" />
    <link rel="next" title="38.3. aepack — Conversion between Python variables and AppleEvent data containers" href="aepack.html" />
    <link rel="prev" title="38.1. gensuitemodule — Generate OSA stub packages" href="gensuitemodule.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
 
    

  </head>
  <body role="document">  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="aepack.html" title="38.3. aepack — Conversion between Python variables and AppleEvent data containers"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="gensuitemodule.html" title="38.1. gensuitemodule — Generate OSA stub packages"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">2.7.12</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li class="nav-item nav-item-2"><a href="macosa.html" accesskey="U">38. MacPython OSA Modules</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-aetools">
<span id="aetools-osa-client-support"></span><h1>38.2. <a class="reference internal" href="#module-aetools" title="aetools: Basic support for sending Apple Events (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetools</span></code></a> &#8212; OSA client support<a class="headerlink" href="#module-aetools" title="Permalink to this headline"></a></h1>
<p>The <a class="reference internal" href="#module-aetools" title="aetools: Basic support for sending Apple Events (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetools</span></code></a> module contains the basic functionality on which Python
AppleScript client support is built. It also imports and re-exports the core
functionality of the <a class="reference internal" href="aetypes.html#module-aetypes" title="aetypes: Python representation of the Apple Event Object Model. (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetypes</span></code></a> and <a class="reference internal" href="aepack.html#module-aepack" title="aepack: Conversion between Python variables and AppleEvent data containers. (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aepack</span></code></a> modules. The stub packages
generated by <a class="reference internal" href="gensuitemodule.html#module-gensuitemodule" title="gensuitemodule: Create a stub package from an OSA dictionary (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">gensuitemodule</span></code></a> import the relevant portions of
<a class="reference internal" href="#module-aetools" title="aetools: Basic support for sending Apple Events (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetools</span></code></a>, 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.</p>
<p>The <a class="reference internal" href="#module-aetools" title="aetools: Basic support for sending Apple Events (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetools</span></code></a> module itself uses the AppleEvent support provided by the
<a class="reference internal" href="carbon.html#module-Carbon.AE" title="Carbon.AE: Interface to the Apple Events toolbox. (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">Carbon.AE</span></code></a> module. This has one drawback: you need access to the window
manager, see section <a class="reference internal" href="../using/mac.html#osx-gui-scripts"><span>Running scripts with a GUI</span></a> for details. This restriction may be
lifted in future releases.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This module has been removed in Python 3.x.</p>
</div>
<p>The <a class="reference internal" href="#module-aetools" title="aetools: Basic support for sending Apple Events (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetools</span></code></a> module defines the following functions:</p>
<dl class="function">
<dt id="aetools.packevent">
<code class="descclassname">aetools.</code><code class="descname">packevent</code><span class="sig-paren">(</span><em>ae</em>, <em>parameters</em>, <em>attributes</em><span class="sig-paren">)</span><a class="headerlink" href="#aetools.packevent" title="Permalink to this definition"></a></dt>
<dd><p>Stores parameters and attributes in a pre-created <code class="docutils literal"><span class="pre">Carbon.AE.AEDesc</span></code> object.
<code class="docutils literal"><span class="pre">parameters</span></code> and <code class="docutils literal"><span class="pre">attributes</span></code> are  dictionaries mapping 4-character OSA
parameter keys to Python objects. The objects are packed using
<code class="docutils literal"><span class="pre">aepack.pack()</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="aetools.unpackevent">
<code class="descclassname">aetools.</code><code class="descname">unpackevent</code><span class="sig-paren">(</span><em>ae</em><span class="optional">[</span>, <em>formodulename</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#aetools.unpackevent" title="Permalink to this definition"></a></dt>
<dd><p>Recursively unpacks a <code class="docutils literal"><span class="pre">Carbon.AE.AEDesc</span></code> event to Python objects. The function
returns the parameter dictionary and the attribute dictionary. The
<code class="docutils literal"><span class="pre">formodulename</span></code> argument is used by generated stub packages to control where
AppleScript classes are looked up.</p>
</dd></dl>

<dl class="function">
<dt id="aetools.keysubst">
<code class="descclassname">aetools.</code><code class="descname">keysubst</code><span class="sig-paren">(</span><em>arguments</em>, <em>keydict</em><span class="sig-paren">)</span><a class="headerlink" href="#aetools.keysubst" title="Permalink to this definition"></a></dt>
<dd><p>Converts a Python keyword argument dictionary <code class="docutils literal"><span class="pre">arguments</span></code> to the format
required by <code class="docutils literal"><span class="pre">packevent</span></code> by replacing the keys, which are Python identifiers,
by the four-character OSA keys according to the mapping specified in
<code class="docutils literal"><span class="pre">keydict</span></code>. Used by the generated suite packages.</p>
</dd></dl>

<dl class="function">
<dt id="aetools.enumsubst">
<code class="descclassname">aetools.</code><code class="descname">enumsubst</code><span class="sig-paren">(</span><em>arguments</em>, <em>key</em>, <em>edict</em><span class="sig-paren">)</span><a class="headerlink" href="#aetools.enumsubst" title="Permalink to this definition"></a></dt>
<dd><p>If the <code class="docutils literal"><span class="pre">arguments</span></code> dictionary contains an entry for <code class="docutils literal"><span class="pre">key</span></code> convert the value
for that entry according to dictionary <code class="docutils literal"><span class="pre">edict</span></code>. This converts human-readable
Python enumeration names to the OSA 4-character codes. Used by the generated
suite packages.</p>
</dd></dl>

<p>The <a class="reference internal" href="#module-aetools" title="aetools: Basic support for sending Apple Events (deprecated) (Mac)"><code class="xref py py-mod docutils literal"><span class="pre">aetools</span></code></a> module defines the following class:</p>
<dl class="class">
<dt id="aetools.TalkTo">
<em class="property">class </em><code class="descclassname">aetools.</code><code class="descname">TalkTo</code><span class="sig-paren">(</span><span class="optional">[</span><em>signature=None</em>, <em>start=0</em>, <em>timeout=0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#aetools.TalkTo" title="Permalink to this definition"></a></dt>
<dd><p>Base class for the proxy used to talk to an application. <code class="docutils literal"><span class="pre">signature</span></code> overrides
the class attribute <code class="docutils literal"><span class="pre">_signature</span></code> (which is usually set by subclasses) and is
the 4-char creator code defining the application to talk to. <code class="docutils literal"><span class="pre">start</span></code> can be
set to true to enable running the application on class instantiation.
<code class="docutils literal"><span class="pre">timeout</span></code> can be specified to change the default timeout used while waiting
for an AppleEvent reply.</p>
</dd></dl>

<dl class="method">
<dt id="aetools.TalkTo._start">
<code class="descclassname">TalkTo.</code><code class="descname">_start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aetools.TalkTo._start" title="Permalink to this definition"></a></dt>
<dd><p>Test whether the application is running, and attempt to start it if not.</p>
</dd></dl>

<dl class="method">
<dt id="aetools.TalkTo.send">
<code class="descclassname">TalkTo.</code><code class="descname">send</code><span class="sig-paren">(</span><em>code</em>, <em>subcode</em><span class="optional">[</span>, <em>parameters</em>, <em>attributes</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#aetools.TalkTo.send" title="Permalink to this definition"></a></dt>
<dd><p>Create the AppleEvent <code class="docutils literal"><span class="pre">Carbon.AE.AEDesc</span></code> for the verb with the OSA designation
<code class="docutils literal"><span class="pre">code,</span> <span class="pre">subcode</span></code> (which are the usual 4-character strings), pack the
<code class="docutils literal"><span class="pre">parameters</span></code> and <code class="docutils literal"><span class="pre">attributes</span></code> into it, send it to the target application,
wait for the reply, unpack the reply with <code class="docutils literal"><span class="pre">unpackevent</span></code> and return the reply
appleevent, the unpacked return values as a dictionary and the return
attributes.</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="gensuitemodule.html"
                        title="previous chapter">38.1. <code class="docutils literal"><span class="pre">gensuitemodule</span></code> &#8212; Generate OSA stub packages</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="aepack.html"
                        title="next chapter">38.3. <code class="docutils literal"><span class="pre">aepack</span></code> &#8212; Conversion between Python variables and AppleEvent data containers</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/aetools.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="aepack.html" title="38.3. aepack — Conversion between Python variables and AppleEvent data containers"
             >next</a> |</li>
        <li class="right" >
          <a href="gensuitemodule.html" title="38.1. gensuitemodule — Generate OSA stub packages"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">2.7.12</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li class="nav-item nav-item-2"><a href="macosa.html" >38. MacPython OSA Modules</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 20, 2016.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
    </div>

  </body>
</html>