1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
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">
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
24 print f.get(f.window(
1).name)
25 </tt></pre></blockquote>
27 <p>is identical to the following piece of AppleScript:
</p>
30 tell application
"Finder"
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-
>Generate OSA Suite...
</tt> for this. For more control run
</p>
41 pythonw .../Lib/plat-mac/gensuitemodule.py --help
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.