~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Mac/Resources/app/Resources/English.lproj/Documentation/scripting.html

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
13
 
 
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>
 
19
        
 
20
<blockquote><pre><tt>
 
21
import Finder
 
22
 
 
23
f = Finder.Finder()
 
24
print f.get(f.window(1).name)
 
25
</tt></pre></blockquote>
 
26
 
 
27
<p>is identical to the following piece of AppleScript:</p>
 
28
 
 
29
<blockquote><pre><tt>
 
30
tell application "Finder"
 
31
        get name of window 1
 
32
end tell
 
33
</tt></pre></blockquote>
 
34
 
 
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>
 
39
 
 
40
<blockquote><tt>
 
41
pythonw .../Lib/plat-mac/gensuitemodule.py --help
 
42
</tt></blockquote>
 
43
 
 
44
<p>from a terminal window.</p>
 
45
 
 
46
<h2>Creating a scriptable application in Python</h2>
 
47
 
 
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.
 
51
 
 
52
</body>
 
53
</html>