PageRenderTime 223ms CodeModel.GetById 121ms app.highlight 1ms RepoModel.GetById 99ms app.codeStats 0ms

/Mac/Resources/app/Resources/English.lproj/Documentation/scripting.html

http://unladen-swallow.googlecode.com/
HTML | 53 lines | 42 code | 11 blank | 0 comment | 0 complexity | b3e37a6d4b2a939ffceeb3fb98568375 MD5 | raw file
 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
15Architecure (OSA, also commonly referred to as AppleScript), allowing
16you to control scriptable applications from your Python program,
17and with a fairly pythonic interface. This piece of
18Python:</p>
19	
20<blockquote><pre><tt>
21import Finder
22
23f = Finder.Finder()
24print 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>
30tell application "Finder"
31	get name of window 1
32end tell
33</tt></pre></blockquote>
34
35<p>To send AppleEvents to an application you must first create the Python
36modules 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>
41pythonw .../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
48You can also create a scriptable application in Python, but this is not
49very well documented. For Carbon
50applications you should look at the <tt>MiniAEFrame</tt> module.
51
52</body>
53</html>