Maintain backwards compatibility with python < 2.3 by dynamically
[python/dscho.git] / Mac / OSXResources / app / Resources / English.lproj / Documentation / scripting.html
blob16321cb28e05ade6e2770602eb4231174cf62853
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
3 <html lang="en">
4 <head>
5 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
6 <title>Controlling other Applications from MacPython</title>
7 <meta name="generator" content="BBEdit 6.5.3">
8 <link rel="SHORTCUT ICON" href="pythonsmall.gif">
9 <META NAME="AppleIcon" CONTENT="pythonsmall.gif">
10 </head>
11 <body>
12 <h1>Controlling other Applications from MacPython</h1>
14 <p>Python has a fairly complete implementation of the Open Scripting
15 Architecure (OSA, also commonly referred to as AppleScript), allowing
16 you to control scriptable applications from your Python program,
17 and with a fairly pythonic interface. This piece of
18 Python:</p>
20 <blockquote><pre><tt>
21 import Finder
23 f = Finder.Finder()
24 print f.get(f.window(1).name)
25 </tt></pre></blockquote>
27 <p>is identical to the following piece of AppleScript:</p>
29 <blockquote><pre><tt>
30 tell application "Finder"
31 get name of window 1
32 end tell
33 </tt></pre></blockquote>
35 <p>To send AppleEvents to an application you must first create the Python
36 modules interfacing to the terminology of the application (what
37 <tt>Script Editor</tt> calls the "Dictionary"). Use the IDE menu command
38 <tt>File-&gt;Generate OSA Suite...</tt> for this. For more control run</p>
40 <blockquote><tt>
41 pythonw .../Lib/plat-mac/gensuitemodule.py --help
42 </tt></blockquote>
44 <p>from a terminal window.</p>
46 <h2>Creating a scriptable application in Python</h2>
48 You can also create a scriptable application in Python, but this is not
49 very well documented. For Carbon
50 applications you should look at the <tt>MiniAEFrame</tt> module.
52 </body>
53 </html>