annotate Mac/Demo/applescript.html @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 8900213764ba
children 391f08a9746b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 <HTML><HEAD><TITLE>Using Open Scripting Extension from Python</TITLE></HEAD>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 <BODY>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 <H1>Using Open Scripting Extension from Python</H1>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 <HR>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 OSA support in Python is still far from complete, and what
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 support there is is likely to change in the forseeable future. Still,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 there is already enough in place to allow you to do some nifty things
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 to other programs from your python program. <P>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 <CITE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 Actually, when we say "AppleScript" in this document we actually mean
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 "the Open Scripting Architecture", there is nothing
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 AppleScript-specific in the Python implementation. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 </CITE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 In this example, we will look at a scriptable application, extract its
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 "AppleScript Dictionary" and generate a Python interface module from
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 that and use that module to control the application. Because we want
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 to concentrate on the OSA details we don't bother with a real
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 user-interface for our application. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 The application we are going to script is Eudora Light, a free mail
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 program from <A HREF="http://www.qualcomm.com">QualComm</A>. This is a
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 very versatile mail-reader, and QualComm has an accompanying
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 commercial version once your needs outgrow Eudora Light. Our program
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 will tell Eudora to send queued mail, retrieve mail or quit. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 <H2>Creating the Python interface module</H2>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 There is a tool in the standard distribution that looks through a file
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 for an 'AETE' or 'AEUT' resource, the internal representation of the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 AppleScript dictionary. This tool is called
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 <CODE>gensuitemodule.py</CODE>, and lives in
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
35 <CODE>Mac:scripts</CODE>. When we start it, it asks us for an input
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 file and we point it to the Eudora Light executable. It starts parsing
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 the AETE resource, and for each AppleEvent suite it finds it prompts
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 us for the filename of the resulting python module. Remember to change
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 folders for the first module, you don't want to clutter up the Eudora
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 folder with your python interfaces. If you want to skip a suite you
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 press cancel and the process continues with the next suite. In the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 case of Eudora, you do <EM>not</EM> want to generate the Required
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 suite, because it will be empty. AppleScript understands that an empty
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 suite means "incorporate the whole standard suite by this name",
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 gensuitemodule does not currently understand this. Creating the empty
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 <CODE>Required_Suite.py</CODE> would hide the correct module of that
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 name from our application. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
49 <BLOCKQUOTE>
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 Time for a sidebar. If you want to re-create
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 <CODE>Required_Suite.py</CODE> or one of the other standard modules
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 you should look in <CODE>System Folder:Extensions:Scripting
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 Additions:Dialects:English Dialect</CODE>, that is where the core
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 AppleEvent dictionaries live. Also, if you are looking for the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 <CODE>Finder_Suite</CODE> interface: don't look in the finder (it has
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 an old System 7.0 scripting suite), look at the extension <CODE>Finder
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 Scripting Extension</CODE>. <p>
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
58 </BLOCKQUOTE>
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 Let's glance at the <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 HREF="scripting/Eudora_Suite.py">Eudora_Suite.py</A> just created. You
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 may want to open Script Editor alongside, and have a look at how it
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 interprets the dictionary. EudoraSuite.py starts with some
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 boilerplate, then come some dictionaries implementing the OSA
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 Enumerations, then a big class definition with methods for each
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 AppleScript Verb and finally some comments. The Enumerations we will
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 skip, it suffices to know that whenever you have to pass an enumerator
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 to a method you can pass the english name and don't have to bother
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 with the 4-letter type code. So, you can say
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 <CODE><PRE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 eudora.notice(occurrence="mail_arrives")
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 </PRE></CODE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 instead of the rather more cryptic
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 <CODE><PRE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 eudora.notice(occurrence="wArv")
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 </PRE></CODE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 The <CODE>Eudora_Suite</CODE> class is the bulk of the code
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 generated. For each verb it contains a method. Each method knows what
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 arguments the verb expects, and it makes handy use of the keyword
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 argument scheme introduced in Python 1.3 to present a palatable
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 interface to the python programmer. You will see that each method
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 calls some routines from <CODE>aetools</CODE>, an auxiliary module
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
84 living in <CODE>Lib:toolbox</CODE> which contains some other nifty
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 AppleEvent tools as well. Have a look at it sometime, there is (of
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 course) no documentation yet. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 The other thing you notice is that each method calls
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 <CODE>self.send</CODE>, but no such method is defined. You will have
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 to provide it by subclassing or multiple inheritance, as we shall see
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 later. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 The module ends with some comments. Sadly, gensuitemodule is not yet
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 able to turn the Object Specifiers into reasonable Python code. For
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 now, if you need object specifiers, you will have to use the routines
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 defined in <CODE>aetools.py</CODE> (and <CODE>aetypes.py</CODE>, which
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 it incorporates). You use these in the form <CODE>aetools.Word(10,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 aetools.Document(1))</CODE> where the corresponding AppleScript
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 terminology would be <CODE>word 10 of the first
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 document</CODE>. Examine the two modules mentioned above along with
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 the comments at the end of your suite module if you need to create
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 more than the standard object specifiers. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 <H2>Using a Python suite module</H2>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 Now that we have created the suite module we can use it in an
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 application. We do this by creating a class that inherits
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 <CODE>Eudora_Suite</CODE> and the <CODE>TalkTo</CODE> class from
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 <CODE>aetools</CODE>. The <CODE>TalkTo</CODE> class is basically a
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 container for the <CODE>send</CODE> method used by the methods from
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 the suite classes. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 Actually, our class will also inherit <CODE>Required_Suite</CODE>,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 because we also need functionality from that suite: the quit
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 command. Gensuitemodule could have created this completely derived
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 class for us, since it has access to all information needed to build
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 the class but unfortunately it does not do so at the moment. All in
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 all, the heart of our program looks like this:
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 <CODE><PRE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 import Eudora_Suite, Required_Suite, aetools
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 class Eudora(aetools.TalkTo, Required_Suite.Required_Suite, \
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 Eudora_Suite.Eudora_Suite):
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 pass
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 </PRE></CODE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 Yes, our class body is <CODE>pass</CODE>, all functionality is already
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 provided by the base classes, the only thing we have to do is glue it
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 together in the right way. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 Looking at the sourcefile <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 HREF="scripting/testeudora.py">testeudora.py</A> we see that it starts
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
133 with some imports. Then we get the class definition
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 for our main object and a constant giving the signature of Eudora. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 This, again, needs a little explanation. There are various ways to
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 describe to AppleScript which program we want to talk to, but the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 easiest one to use (from Python, at least) is creator
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 signature. Application name would be much nicer, but Python currently
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 does not have a module that interfaces to the Finder database (which
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 would allow us to map names to signatures). The other alternative,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 <CODE>ChooseApplication</CODE> from the program-to-program toolbox, is
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 also not available from Python at the moment. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144
4318
97d3652e57d3 - Regenerated suites
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
145 If you specify the application by creator you can specify an optional
97d3652e57d3 - Regenerated suites
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
146 <CODE>start</CODE> parameter, which will cause the application to be
97d3652e57d3 - Regenerated suites
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
147 started if it is not running. <P>
97d3652e57d3 - Regenerated suites
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
148
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 The main program itself is a wonder of simplicity. We create the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 object that talks to Eudora (passing the signature as argument), ask
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 the user what she wants and call the appropriate method of the talker
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 object. The use of keyword arguments with the same names as used by
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 AppleScript make passing the parameters a breeze. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 The exception handling does need a few comments, though. Since
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 AppleScript is basically a connectionless RPC protocol nothing happens
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 when we create to talker object. Hence, if the destination application
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 is not running we will not notice until we send our first
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 command. There is another thing to note about errors returned by
4553
8900213764ba Added reference to pdf documentation and bbpy, correctly explained
Jack Jansen <jack.jansen@cwi.nl>
parents: 4318
diff changeset
160 AppleScript calls: <CODE>MacOS.Error</CODE> is raised for
8900213764ba Added reference to pdf documentation and bbpy, correctly explained
Jack Jansen <jack.jansen@cwi.nl>
parents: 4318
diff changeset
161 all of the errors that are known to be <CODE>OSErr</CODE>-type errors,
8900213764ba Added reference to pdf documentation and bbpy, correctly explained
Jack Jansen <jack.jansen@cwi.nl>
parents: 4318
diff changeset
162 server generated errors raise <CODE>aetools.Error</CODE>. <p>
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 That concludes our simple example. Again, let me emphasize that
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 scripting support in Python is not very complete at the moment, and
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166 the details of how to use AppleEvents will definitely change in the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 near future. This will not only fix all the ideosyncracies noted in
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 this document but also break existing programs, since the current
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 suite organization will have to change to fix some of the problems.
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 Still, if you want to experiment with AppleEvents right now: go ahead!
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 <p>