summaryrefslogtreecommitdiffstats
path: root/Mac/OSXResources/app/Resources/English.lproj/Documentation/scripting.html
blob: 58b1fe263bce801639428b7a81fe68939de68ba4 (plain)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<title>Controlling other Applications from MacPython</title>
	<meta name="generator" content="BBEdit 6.5.3">
	<link rel="SHORTCUT ICON" href="pythonsmall.gif">
	<META NAME="AppleIcon" CONTENT="pythonsmall.gif">
</head>
<body>
<h1>Controlling other Applications from MacPython</h1>

<p>Python has a fairly complete implementation of the Open Scripting
Architecure (OSA, also commonly referred to as AppleScript), allowing
you to control scriptable applications from your Python program,
and with a fairly pythonic interface. This piece of
Python:</p>
	
<blockquote><tt><pre>
import Finder

f = Finder.Finder()
print f.get(f.window(1).name)
</pre></tt></blockquote>

<p>is identical to the following piece of AppleScript:</p>

<blockquote><tt><pre>
tell application "Finder"
	get name of window 1
end tell
</pre></tt></blockquote>

<p>To send AppleEvents to an application you must first create the Python
modules interfacing to the terminology of the application (what
<tt>Script Editor</tt> calls the "Dictionary"). Use the IDE menu command
<tt>File->Generate OSA Suite...</tt> for this. For more control run</p>

<blockquote><tt>
pythonw .../Lib/plat-mac/gensuitemodule.py --help
</tt></blockquote>

<p>from a terminal window.</p>

<h2>Creating a scriptable application in Python</h2>

You can also create a scriptable application in Python, but this is not
very well documented. For Carbon
applications you should look at the <tt>MiniAEFrame</tt> module.

</body>
</html>