rb-appscript 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +30 -0
- data/LICENSE +1 -1
- data/README +7 -3
- data/TODO +7 -1
- data/doc/aem-manual/01_introduction.html +23 -9
- data/doc/aem-manual/02_apioverview.html +25 -11
- data/doc/aem-manual/03_packingandunpackingdata.html +22 -17
- data/doc/aem-manual/04_references.html +49 -36
- data/doc/aem-manual/05_targettingapplications.html +25 -14
- data/doc/aem-manual/06_buildingandsendingevents.html +47 -21
- data/doc/aem-manual/07_findapp.html +22 -11
- data/doc/aem-manual/08_examples.html +21 -10
- data/doc/aem-manual/index.html +28 -12
- data/doc/appscript-manual/01_introduction.html +40 -27
- data/doc/appscript-manual/02_aboutappscripting.html +28 -15
- data/doc/appscript-manual/03_quicktutorial.html +29 -16
- data/doc/appscript-manual/04_gettinghelp.html +31 -16
- data/doc/appscript-manual/05_keywordconversion.html +23 -10
- data/doc/appscript-manual/06_classesandenums.html +32 -19
- data/doc/appscript-manual/07_applicationobjects.html +31 -18
- data/doc/appscript-manual/08_realvsgenericreferences.html +23 -11
- data/doc/appscript-manual/09_referenceforms.html +33 -20
- data/doc/appscript-manual/10_referenceexamples.html +30 -17
- data/doc/appscript-manual/11_applicationcommands.html +25 -13
- data/doc/appscript-manual/12_commandexamples.html +26 -15
- data/doc/appscript-manual/13_performanceissues.html +46 -20
- data/doc/appscript-manual/14_notes.html +29 -19
- data/doc/appscript-manual/index.html +27 -11
- data/doc/full.css +95 -9
- data/doc/index.html +27 -10
- data/doc/mactypes-manual/01_introduction.html +56 -0
- data/doc/mactypes-manual/02_aliasclass.html +134 -0
- data/doc/mactypes-manual/03_fileurlclass.html +136 -0
- data/doc/mactypes-manual/04_unitsclass.html +102 -0
- data/doc/mactypes-manual/index.html +26 -227
- data/doc/osax-manual/01_introduction.html +69 -0
- data/doc/osax-manual/02_interface.html +149 -0
- data/doc/osax-manual/03_examples.html +75 -0
- data/doc/osax-manual/04_notes.html +80 -0
- data/doc/osax-manual/index.html +26 -195
- data/doc/rb-appscript-logo.png +0 -0
- data/rb-appscript.gemspec +2 -2
- data/sample/TextEdit_demo.rb +1 -1
- data/src/lib/_aem/aemreference.rb +1 -1
- data/src/lib/_aem/codecs.rb +42 -8
- data/src/lib/_aem/connect.rb +3 -1
- data/src/lib/_aem/findapp.rb +1 -1
- data/src/lib/_aem/mactypes.rb +1 -1
- data/src/lib/_aem/send.rb +162 -142
- data/src/lib/_aem/typewrappers.rb +2 -2
- data/src/lib/_appscript/defaultterminology.rb +76 -46
- data/src/lib/_appscript/referencerenderer.rb +1 -1
- data/src/lib/_appscript/reservedkeywords.rb +2 -2
- data/src/lib/_appscript/safeobject.rb +1 -1
- data/src/lib/_appscript/terminology.rb +30 -19
- data/src/lib/aem.rb +1 -6
- data/src/lib/appscript.rb +65 -20
- data/src/lib/osax.rb +21 -18
- data/src/rbae.c +1 -1
- data/test/test_appscriptcommands.rb +1 -1
- metadata +12 -3
@@ -2,7 +2,7 @@
|
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
3
|
<head>
|
4
4
|
|
5
|
-
<title>appscript | 2. About Application Scripting</title>
|
5
|
+
<title>rb-appscript manual | 2. About Application Scripting</title>
|
6
6
|
|
7
7
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
8
8
|
<style type="text/css" media="all"><!--@import url(../full.css);--></style>
|
@@ -10,19 +10,30 @@
|
|
10
10
|
</head>
|
11
11
|
<body>
|
12
12
|
|
13
|
-
<h1
|
13
|
+
<h1><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
|
14
14
|
|
15
15
|
<!-- top navigation -->
|
16
16
|
<div class="navbar">
|
17
|
-
|
18
|
-
|
17
|
+
<a href="01_introduction.html">Previous</a> •
|
18
|
+
<a href="index.html">Up</a> •
|
19
|
+
<a href="03_quicktutorial.html">Next</a>
|
20
|
+
|
21
|
+
<span>
|
22
|
+
<strong><a href="../appscript-manual/index.html">appscript</a></strong> /
|
23
|
+
<a href="../mactypes-manual/index.html">mactypes</a> /
|
24
|
+
<a href="../osax-manual/index.html">osax</a> /
|
25
|
+
<a href="../aem-manual/index.html">aem</a>
|
26
|
+
</span>
|
19
27
|
</div>
|
20
28
|
|
21
29
|
<!-- content -->
|
22
30
|
<div id="content">
|
31
|
+
|
32
|
+
<h2>2. About Application Scripting</h2>
|
33
|
+
|
23
34
|
<p>This chapter introduces the main concepts behind Apple event-based application scripting. However, if you just can't wait to begin using appscript, you can skip to the tutorial in <a href="03_quicktutorial.html">chapter 3</a> and return to this chapter later on.</p>
|
24
35
|
|
25
|
-
<
|
36
|
+
<h3>What are Apple events?</h3>
|
26
37
|
|
27
38
|
<p>Apple events are a high-level message-based form of Interprocess Communication (IPC; also known as Interapplication Communication, or IAC), used to communicate between local or remote application processes (and, in some cases, within the same process).</p>
|
28
39
|
|
@@ -59,7 +70,7 @@
|
|
59
70
|
<p>Applications may respond to an incoming Apple event by sending a reply event back to the client application. The reply event may contain either a return value, if there is one, or an error description if it was unable to handle the event as requested. For example, executing the command <code>app('TextEdit').name.get</code> in a Ruby interpreter sends TextEdit a <code>code/getd</code> event containing an object specifier identifying the <code>name</code> property of its root <code>application</code> object. TextEdit processes this event, then sends a reply event containing the string '<tt>TextEdit</tt>' back to the Ruby interpreter, where it is displayed as the command's result. This exchange is usually performed synchronously, appearing to the user as a simple remote procedure call. Asynchronous messaging is also supported, though is not normally used in application scripting.</p>
|
60
71
|
|
61
72
|
|
62
|
-
<
|
73
|
+
<h3>What is a scriptable application?</h3>
|
63
74
|
|
64
75
|
<p>A scriptable (or 'AppleScriptable') application is an application that provides an Apple event interface intended for third-party (e.g. end-user) use. The application implements one or more event handlers that respond to corresponding events, and may also support the Apple Event Object Model. While this interface may be regarded as an API, the emphasis is on providing a high-level <em>user interface</em> that is peer to other users interfaces the application may have (GUI, CLI, web, etc.) and accessible to end-users as much as developers.</p>
|
65
76
|
|
@@ -78,7 +89,7 @@
|
|
78
89
|
<p>(Note that the <code>aete</code> and <code>sdef</code> formats do not provide an exhaustive description of the application's scripting interface, and additional documentation is usually required - if not always provided - to form a complete understanding of that interface and how to use it effectively.)</p>
|
79
90
|
|
80
91
|
|
81
|
-
<
|
92
|
+
<h3>What is the Apple Event Object Model?</h3>
|
82
93
|
|
83
94
|
<p>The Apple Event Object Model (AEOM) is an idealised, user-oriented representation of the application's internal data model, allowing clients to identify and manipulate parts of that structure via Apple events. An incoming Apple event representing a particular command (get, set, move, etc.) is unpacked, and any object specifiers in its parameter list are evaluated against the application's AEOM to identify the user-level object(s) upon which the command should act. The command is then applied these objects, with the AEOM translating this into operations upon the application's implementation-level objects. These implementation-level objects are mostly user-data objects in the application's Model layer, plus a few GUI objects of interest to scripters (such as those representing document windows). The internal architecture of a typical scriptable desktop application might look something like this:</p>
|
84
95
|
|
@@ -99,7 +110,7 @@
|
|
99
110
|
</div>
|
100
111
|
|
101
112
|
|
102
|
-
<
|
113
|
+
<h3>How does the AEOM work?</h3>
|
103
114
|
|
104
115
|
<p>The AEOM is a tree structure made up of objects. These objects may have attributes (descriptive values such as class, name, id, size, bounds; usually primitive AE types but occasionally other application objects), e.g.:</p>
|
105
116
|
|
@@ -175,7 +186,7 @@ app('TextEdit').documents[1].text.paragraphs</code></pre>
|
|
175
186
|
|
176
187
|
</div>
|
177
188
|
|
178
|
-
<
|
189
|
+
<h3>What is appscript?</h3>
|
179
190
|
|
180
191
|
<p>Appscript is a high-level Ruby-to-Apple Event Manager bridge, intended for use by both developers and end-users. The appscript architecture consists of three layers:</p>
|
181
192
|
|
@@ -212,7 +223,7 @@ app('TextEdit').documents[1].text.paragraphs</code></pre>
|
|
212
223
|
|
213
224
|
|
214
225
|
|
215
|
-
<
|
226
|
+
<h3>Additional resources</h3>
|
216
227
|
|
217
228
|
<p>Background information links can be found on the <a href="http://rb-appscript.rubyforge.org">rb-appscript website</a>.</p>
|
218
229
|
|
@@ -225,12 +236,14 @@ app('TextEdit').documents[1].text.paragraphs</code></pre>
|
|
225
236
|
</div>
|
226
237
|
|
227
238
|
<!-- bottom navigation -->
|
228
|
-
|
229
|
-
|
230
|
-
|
239
|
+
|
240
|
+
<div class="footer">
|
241
|
+
<a href="01_introduction.html">Previous</a> •
|
242
|
+
<a href="index.html">Up</a> •
|
243
|
+
<a href="03_quicktutorial.html">Next</a>
|
244
|
+
|
245
|
+
<span>© 2006-2008 HAS</span>
|
231
246
|
</div>
|
232
247
|
|
233
|
-
<!--footer-->
|
234
|
-
<p class="footer">© 2006-2008 HAS</p>
|
235
248
|
</body>
|
236
249
|
</html>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
3
|
<head>
|
4
4
|
|
5
|
-
<title>appscript | 3. Quick Tutorial</title>
|
5
|
+
<title>rb-appscript manual | 3. Quick Tutorial</title>
|
6
6
|
|
7
7
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
8
8
|
<style type="text/css" media="all"><!--@import url(../full.css);--></style>
|
@@ -10,19 +10,30 @@
|
|
10
10
|
</head>
|
11
11
|
<body>
|
12
12
|
|
13
|
-
<h1
|
13
|
+
<h1><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
|
14
14
|
|
15
15
|
<!-- top navigation -->
|
16
16
|
<div class="navbar">
|
17
|
-
|
18
|
-
|
17
|
+
<a href="02_aboutappscripting.html">Previous</a> •
|
18
|
+
<a href="index.html">Up</a> •
|
19
|
+
<a href="04_gettinghelp.html">Next</a>
|
20
|
+
|
21
|
+
<span>
|
22
|
+
<strong><a href="../appscript-manual/index.html">appscript</a></strong> /
|
23
|
+
<a href="../mactypes-manual/index.html">mactypes</a> /
|
24
|
+
<a href="../osax-manual/index.html">osax</a> /
|
25
|
+
<a href="../aem-manual/index.html">aem</a>
|
26
|
+
</span>
|
19
27
|
</div>
|
20
28
|
|
21
29
|
<!-- content -->
|
22
30
|
<div id="content">
|
31
|
+
|
32
|
+
<h2>3. Quick Tutorial</h2>
|
33
|
+
|
23
34
|
<p>The following tutorial provides a practical taste of application scripting with appscript. Later chapters cover the technical details of appscript usage that are mostly skimmed over here.</p>
|
24
35
|
|
25
|
-
<
|
36
|
+
<h3>'Hello World' tutorial</h3>
|
26
37
|
|
27
38
|
<p>This tutorial uses appscript, TextEdit and the interactive command line Ruby interpreter to perform a simple 'Hello World' exercise.</p>
|
28
39
|
|
@@ -33,7 +44,7 @@
|
|
33
44
|
<pre><code>brian% irb
|
34
45
|
irb(main):001:0></code></pre>
|
35
46
|
|
36
|
-
<
|
47
|
+
<h4>Target TextEdit</h4>
|
37
48
|
|
38
49
|
<p>The first step is to import the appscript module, <code>Appscript</code>, which provides the following functions and classes: <code>app</code>, <code>con</code>, <code>its</code>, <code>CommandError</code> and <code>ApplicationNotFoundError</code>.</p>
|
39
50
|
|
@@ -49,7 +60,7 @@ irb> include Appscript
|
|
49
60
|
|
50
61
|
<p>The application may be identified by name, path, bundle ID, creator type, Unix process id, or, if running remotely, URL. If the application is identified by name, path, bundle ID or creator type and is not already running, it will be launched automatically for you.</p>
|
51
62
|
|
52
|
-
<
|
63
|
+
<h4>Create a new document</h4>
|
53
64
|
|
54
65
|
<p>First, create a new TextEdit document by making a new <code>document</code> object. This is done using the <code>make</code> command, passing it a single keyword parameter, <code>:new => :document</code>, indicating the type of object to create:</p>
|
55
66
|
|
@@ -65,7 +76,7 @@ irb> include Appscript
|
|
65
76
|
<pre><code>irb> doc = te.make(:new => :document)
|
66
77
|
=> app("/Applications/TextEdit.app").documents[1]</code></pre>
|
67
78
|
|
68
|
-
<
|
79
|
+
<h4>Set the document's content</h4>
|
69
80
|
|
70
81
|
<p>The next step is to set the document's content to the string <code>"Hello World"</code>. Every TextEdit document has a property, <code>text</code>, that represents the entire text of the document. This property is both readable and writeable, allowing you to retrieve and/or modify the document's textual content as unstyled unicode text.</p>
|
71
82
|
|
@@ -82,7 +93,7 @@ irb> include Appscript
|
|
82
93
|
|
83
94
|
<p>Appscript converts this second form to the first form internally, so the end result is exactly the same. Appscript supports several such special cases, and these are described in the <a href="11_applicationcommands.html">Application Commands</a> chapter. Using these special cases produces more elegant, readable source code, and is recommended.</p>
|
84
95
|
|
85
|
-
<
|
96
|
+
<h4>Get the document's content</h4>
|
86
97
|
|
87
98
|
<p>Retrieving the document's text is done using the <code>get</code> command:</p>
|
88
99
|
|
@@ -117,7 +128,7 @@ irb> te.documents.text.get
|
|
117
128
|
|
118
129
|
|
119
130
|
|
120
|
-
<
|
131
|
+
<h4>More on <code>make</code></h4>
|
121
132
|
|
122
133
|
<p>The above exercise uses two commands to create a new TextEdit document containing the text '<tt>Hello World</tt>'. It is also possible to perform both operations using the <code>make</code> command alone by passing the value for the new document's <code>text</code> property via the <code>make</code> command's optional <code>with_properties</code> parameter:</p>
|
123
134
|
|
@@ -127,7 +138,7 @@ irb> te.documents.text.get
|
|
127
138
|
<p>Incidentally, you might note that every time the <code>make</code> command is used, it returns a reference to document <em>1</em>. TextEdit identifies its <code>document</code> objects according to the stacking order of their windows, with document 1 being frontmost. When the window stacking order changes, whether as a result of a script command or GUI-based interaction, so does the order of their corresponding <code>document</code> objects. This means that a previously created reference such as <code>app('/Applications/TextEdit.app').documents[1]</code> may now identify a different <code>document</code> object to before! Some applications prefer to return references that identify objects by name or unique ID rather than index to reduce or eliminate the potential for confusion, but it's an issue you should be aware of, particularly with long-running scripts where there is greater opportunity for unexpected third-party interactions to throw a spanner in the works.</p>
|
128
139
|
|
129
140
|
|
130
|
-
<
|
141
|
+
<h4>More on manipulating <code>text</code></h4>
|
131
142
|
|
132
143
|
<p>In addition to getting and setting a document's entire text by applying <code>get</code> and <code>set</code> commands to <code>text</code> property, it's also possible to manipulate selected sections of a document's text directly. TextEdit's <code>text</code> property contains a <code>text</code> object, which in turn has <code>character</code>, <code>word</code> and <code>paragraph</code> elements, all of which can be manipulated using a variety of commands: <code>get</code>, <code>set</code>, <code>make</code>, <code>move</code>, <code>delete</code>, etc. For example, to set the size of the first character of every paragraph of the front document to 24pt:</p>
|
133
144
|
|
@@ -145,12 +156,14 @@ irb> te.documents.text.get
|
|
145
156
|
</div>
|
146
157
|
|
147
158
|
<!-- bottom navigation -->
|
148
|
-
|
149
|
-
|
150
|
-
|
159
|
+
|
160
|
+
<div class="footer">
|
161
|
+
<a href="02_aboutappscripting.html">Previous</a> •
|
162
|
+
<a href="index.html">Up</a> •
|
163
|
+
<a href="04_gettinghelp.html">Next</a>
|
164
|
+
|
165
|
+
<span>© 2006-2008 HAS</span>
|
151
166
|
</div>
|
152
167
|
|
153
|
-
<!--footer-->
|
154
|
-
<p class="footer">© 2006-2008 HAS</p>
|
155
168
|
</body>
|
156
169
|
</html>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
3
|
<head>
|
4
4
|
|
5
|
-
<title>appscript | 4. Getting Help</title>
|
5
|
+
<title>rb-appscript manual | 4. Getting Help</title>
|
6
6
|
|
7
7
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
8
8
|
<style type="text/css" media="all"><!--@import url(../full.css);--></style>
|
@@ -10,21 +10,32 @@
|
|
10
10
|
</head>
|
11
11
|
<body>
|
12
12
|
|
13
|
-
<h1
|
13
|
+
<h1><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
|
14
14
|
|
15
15
|
<!-- top navigation -->
|
16
16
|
<div class="navbar">
|
17
|
-
|
18
|
-
|
17
|
+
<a href="03_quicktutorial.html">Previous</a> •
|
18
|
+
<a href="index.html">Up</a> •
|
19
|
+
<a href="05_keywordconversion.html">Next</a>
|
20
|
+
|
21
|
+
<span>
|
22
|
+
<strong><a href="../appscript-manual/index.html">appscript</a></strong> /
|
23
|
+
<a href="../mactypes-manual/index.html">mactypes</a> /
|
24
|
+
<a href="../osax-manual/index.html">osax</a> /
|
25
|
+
<a href="../aem-manual/index.html">aem</a>
|
26
|
+
</span>
|
19
27
|
</div>
|
20
28
|
|
21
29
|
<!-- content -->
|
22
30
|
<div id="content">
|
31
|
+
|
32
|
+
<h2>4. Getting Help</h2>
|
33
|
+
|
23
34
|
<p>When developing appscript-based scripts, there are several ways to get information about applications' scripting interfaces: the ASDictionary application and its bundled <code>asdict</code> command-line tool, appscript's powerful built-in <code>help</code> method, and introspection.</p>
|
24
35
|
|
25
36
|
|
26
37
|
|
27
|
-
<
|
38
|
+
<h3>ASDictionary</h3>
|
28
39
|
|
29
40
|
<p>ASDictionary, available from the appscript website's <a href="http://rb-appscript.rubyforge.org/downloads.html">Downloads page</a>, provides a convenient GUI interface for exporting application terminology resources in plain text and HTML formats. ASDictionary can export HTML dictionaries in both single-file format and a frame-based format similar to rdoc's.</p>
|
30
41
|
|
@@ -32,7 +43,7 @@
|
|
32
43
|
|
33
44
|
|
34
45
|
|
35
|
-
<
|
46
|
+
<h3>Built-in <code>help</code> method</h3>
|
36
47
|
|
37
48
|
<p>Appscript's <code>Application</code> and <code>Reference</code> classes include a powerful interactive help system that allows you to explore applications' scripting interfaces from within running scripts and Ruby's interactive <code>irb</code> interpreter. The <code>help</code> method can provide information on any suite, class, command or reference, and display the inheritance and relationships for a selected class or the entire application.</p>
|
38
49
|
|
@@ -94,7 +105,7 @@ app('TextEdit').documents.help('-t count -t close')</code></pre>
|
|
94
105
|
|
95
106
|
|
96
107
|
|
97
|
-
<
|
108
|
+
<h3>Introspection</h3>
|
98
109
|
|
99
110
|
<p>In addition to supporting Ruby's standard <code>#methods</code> and <code>#respond_to?</code> methods, appscript's <code>Application</code> and <code>Reference</code> classes also define several instance methods for obtaining information on the target application: </p>
|
100
111
|
|
@@ -128,12 +139,12 @@ p te.parameters('make')
|
|
128
139
|
# ["at", "new", "with_data", "with_properties"]</code></pre>
|
129
140
|
|
130
141
|
|
131
|
-
<
|
142
|
+
<h3>Notes</h3>
|
132
143
|
|
133
144
|
<p>While appscript's documentation systems try to be reasonably forgiving of flawed or faulty terminology resources, there may be a few particularly problematic applications on which they fail. Should this happen, use ASDictionary to export the application's terminology in plain text format instead.</p>
|
134
145
|
|
135
146
|
|
136
|
-
<
|
147
|
+
<h3>Other sources of help</h3>
|
137
148
|
|
138
149
|
<ul>
|
139
150
|
<li>The <code>sample</code> folder contains example scripts demonstrating a range of common tasks.</li>
|
@@ -142,19 +153,23 @@ p te.parameters('make')
|
|
142
153
|
|
143
154
|
<li>Look for third-party scripts that provide examples of use (though many of these scripts will be written in AppleScript rather than Ruby).</li>
|
144
155
|
|
145
|
-
<li>The <a href="http://
|
156
|
+
<li>The <a href="http://appscript.sourceforge.net/tools.html">ASTranslate</a> tool can be used to convert application commands from AppleScript to Ruby syntax.</li>
|
157
|
+
|
158
|
+
<li>The <a href="http://appscript.sourceforge.net">appscript website</a> has links to mailing lists and other general resources.</li>
|
146
159
|
</ul>
|
147
160
|
|
148
161
|
|
149
162
|
</div>
|
150
163
|
|
151
164
|
<!-- bottom navigation -->
|
152
|
-
|
153
|
-
|
154
|
-
|
165
|
+
|
166
|
+
<div class="footer">
|
167
|
+
<a href="03_quicktutorial.html">Previous</a> •
|
168
|
+
<a href="index.html">Up</a> •
|
169
|
+
<a href="05_keywordconversion.html">Next</a>
|
170
|
+
|
171
|
+
<span>© 2006-2008 HAS</span>
|
155
172
|
</div>
|
156
173
|
|
157
|
-
<!--footer-->
|
158
|
-
<p class="footer">© 2006-2008 HAS</p>
|
159
174
|
</body>
|
160
|
-
</html>
|
175
|
+
</html>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
3
|
<head>
|
4
4
|
|
5
|
-
<title>appscript | 5. Keyword Conversion</title>
|
5
|
+
<title>rb-appscript manual | 5. Keyword Conversion</title>
|
6
6
|
|
7
7
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
8
8
|
<style type="text/css" media="all"><!--@import url(../full.css);--></style>
|
@@ -10,17 +10,28 @@
|
|
10
10
|
</head>
|
11
11
|
<body>
|
12
12
|
|
13
|
-
<h1
|
13
|
+
<h1><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
|
14
14
|
|
15
15
|
<!-- top navigation -->
|
16
16
|
<div class="navbar">
|
17
|
-
|
18
|
-
|
17
|
+
<a href="04_gettinghelp.html">Previous</a> •
|
18
|
+
<a href="index.html">Up</a> •
|
19
|
+
<a href="06_classesandenums.html">Next</a>
|
20
|
+
|
21
|
+
<span>
|
22
|
+
<strong><a href="../appscript-manual/index.html">appscript</a></strong> /
|
23
|
+
<a href="../mactypes-manual/index.html">mactypes</a> /
|
24
|
+
<a href="../osax-manual/index.html">osax</a> /
|
25
|
+
<a href="../aem-manual/index.html">aem</a>
|
26
|
+
</span>
|
19
27
|
</div>
|
20
28
|
|
21
29
|
<!-- content -->
|
22
30
|
<div id="content">
|
23
|
-
|
31
|
+
|
32
|
+
<h2>5. Keyword Conversion</h2>
|
33
|
+
|
34
|
+
<h3>Keyword conversion</h3>
|
24
35
|
|
25
36
|
<p>Because application terminology resources specify AppleScript-style keywords for class, property, command, etc. names, appscript uses the following rules to translate these keywords to legal Ruby identifiers:</p>
|
26
37
|
|
@@ -80,12 +91,14 @@ id wait_reply</code></pre>
|
|
80
91
|
</ul>
|
81
92
|
|
82
93
|
<!-- bottom navigation -->
|
83
|
-
|
84
|
-
|
85
|
-
|
94
|
+
|
95
|
+
<div class="footer">
|
96
|
+
<a href="04_gettinghelp.html">Previous</a> •
|
97
|
+
<a href="index.html">Up</a> •
|
98
|
+
<a href="06_classesandenums.html">Next</a>
|
99
|
+
|
100
|
+
<span>© 2006-2008 HAS</span>
|
86
101
|
</div>
|
87
102
|
|
88
|
-
<!--footer-->
|
89
|
-
<p class="footer">© 2006-2008 HAS</p>
|
90
103
|
</body>
|
91
104
|
</html>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
3
|
<head>
|
4
4
|
|
5
|
-
<title>appscript | 6. Classes and Enumerated Types</title>
|
5
|
+
<title>rb-appscript manual | 6. Classes and Enumerated Types</title>
|
6
6
|
|
7
7
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
8
8
|
<style type="text/css" media="all"><!--@import url(../full.css);--></style>
|
@@ -10,17 +10,28 @@
|
|
10
10
|
</head>
|
11
11
|
<body>
|
12
12
|
|
13
|
-
<h1
|
13
|
+
<h1><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
|
14
14
|
|
15
15
|
<!-- top navigation -->
|
16
16
|
<div class="navbar">
|
17
|
-
|
18
|
-
|
17
|
+
<a href="05_keywordconversion.html">Previous</a> •
|
18
|
+
<a href="index.html">Up</a> •
|
19
|
+
<a href="07_applicationobjects.html">Next</a>
|
20
|
+
|
21
|
+
<span>
|
22
|
+
<strong><a href="../appscript-manual/index.html">appscript</a></strong> /
|
23
|
+
<a href="../mactypes-manual/index.html">mactypes</a> /
|
24
|
+
<a href="../osax-manual/index.html">osax</a> /
|
25
|
+
<a href="../aem-manual/index.html">aem</a>
|
26
|
+
</span>
|
19
27
|
</div>
|
20
28
|
|
21
29
|
<!-- content -->
|
22
30
|
<div id="content">
|
23
|
-
|
31
|
+
|
32
|
+
<h2>6. Classes and Enumerated Types</h2>
|
33
|
+
|
34
|
+
<h3>Appscript keywords</h3>
|
24
35
|
|
25
36
|
<p>For your convenience, appscript represents Apple event type names and application-specific class and enumerator names as Ruby symbols. Examples:</p>
|
26
37
|
|
@@ -45,7 +56,7 @@
|
|
45
56
|
|
46
57
|
AEM::AEEnum.new('xyz ')</code></pre>
|
47
58
|
|
48
|
-
<
|
59
|
+
<h3>Common AE types</h3>
|
49
60
|
|
50
61
|
<table width="100%" summary="AE-Ruby type mappings">
|
51
62
|
<thead>
|
@@ -78,16 +89,16 @@ AEM::AEEnum.new('xyz ')</code></pre>
|
|
78
89
|
<p>(Note that types marked with '*' are officially deprecated and/or their use discouraged in Mac OS X. They remain supported to ensure backwards compatibility with older applications that may use them.)</p>
|
79
90
|
|
80
91
|
|
81
|
-
<
|
92
|
+
<h3>Type mapping notes</h3>
|
82
93
|
|
83
94
|
<p>While AEM-Ruby type conversions generally work quite seamlessly, it is sometimes useful to know some of the details involved, particularly when troubleshooting code that deals with older or buggy applications.</p>
|
84
95
|
|
85
|
-
<
|
96
|
+
<h4>Numbers</h4>
|
86
97
|
|
87
98
|
<p>When packing a <code>Bignum</code>, appscript will pack it either as a 32-bit integer (most preferred), 64-bit integer, or 64-bit float (least preferred), depending on the value's size.</p>
|
88
99
|
|
89
100
|
|
90
|
-
<
|
101
|
+
<h4>Strings</h4>
|
91
102
|
|
92
103
|
<p>Because Ruby lacks a native Unicode class, appscript unpacks all text-related AE types (<code>typeChar</code>, <code>typeUnicodeText</code>, etc.) as UTF8-encoded Ruby strings.</p>
|
93
104
|
|
@@ -104,7 +115,7 @@ $KCODE = "UTF8"</code></pre>
|
|
104
115
|
<p>Note that while <code>typeUnicodeText</code> is formally deprecated in Mac OS X 10.4+ in favour of <code>typeUTF8Text</code> and <code>typeUTF16ExternalRepresentation</code>, it is still in common usage so appscript continues to use it to ensure the broadest compatibility with existing scriptable applications.</p>
|
105
116
|
|
106
117
|
|
107
|
-
<
|
118
|
+
<h4>Filesystem references</h4>
|
108
119
|
|
109
120
|
<p>The <code>typeAlias</code> AE type represents a filesystem object, and will continue to point to that object even if it's renamed or moved to another location on the same disk. The <code>typeFSRef</code> and <code>typeFileURL</code> types represent a filesystem location. Both can represent existing locations; the <code>typeFileURL</code> type can also be used to specify locations that don't already exist.</p>
|
110
121
|
|
@@ -119,24 +130,24 @@ $KCODE = "UTF8"</code></pre>
|
|
119
130
|
<p>Also be aware that some applications may not support coercions to all AE file types; you'll need to experiment to find out which coercions are supported.</p>
|
120
131
|
|
121
132
|
|
122
|
-
<
|
133
|
+
<h4>Records</h4>
|
123
134
|
|
124
135
|
<p>The <code>typeAERecord</code> AE type is a struct-like data structure containing zero or more properties. Appscript represents AE records as Ruby hashes. The keys in this hash are usually symbols representing appscript-style property names, although they may also be <code>AEM::AEType</code> values or strings.</p>
|
125
136
|
|
126
137
|
<p>If a hash contains a <code>:class_</code> (or <code>AEM::AEType.new('pcls')</code>) key, appscript will pack the remaining items into an AE record, then coerce it to the type specified by this 'class' property. Similarly, when unpacking an record-like AEDesc with a custom type code, appscript will unpack it as a hash with the type represented by a <code>:class_</code> entry.</p>
|
127
138
|
|
128
139
|
|
129
|
-
<
|
140
|
+
<h4>Types and enumerators</h4>
|
130
141
|
|
131
142
|
<p>The <code>typeType</code> and <code>typeEnumerated</code> AE types are unpacked as Ruby symbols when the corresponding terminology is available, otherwise they are unpacked as <code>AEM::AEType</code> and <code>AEM::AEEnum</code> respectively.</td></tr>
|
132
143
|
|
133
144
|
|
134
|
-
<
|
145
|
+
<h4>Unit types</h4>
|
135
146
|
|
136
147
|
<p>Unit type values are represented by instances of the <code>MacTypes::Units</code> class, e.g. <code>MacTypes::Units.inches(3.0)</code>. See the <a href="../mactypes-manual/index.html">mactypes manual</a> for more information.</p>
|
137
148
|
|
138
149
|
|
139
|
-
<
|
150
|
+
<h4>Miscellaneous types</h4>
|
140
151
|
|
141
152
|
<p>The Apple Event Manager defines many other AE types whose names and codes are defined by appscript for completeness. A few of these types are of occasional interest to users, the rest can simply be ignored. In most cases, values of these types will be represented by raw <code>AE::AEDesc</code> instances as appscript doesn't automatically convert them to native objects.</p>
|
142
153
|
|
@@ -144,12 +155,14 @@ $KCODE = "UTF8"</code></pre>
|
|
144
155
|
</div>
|
145
156
|
|
146
157
|
<!-- bottom navigation -->
|
147
|
-
|
148
|
-
|
149
|
-
|
158
|
+
|
159
|
+
<div class="footer">
|
160
|
+
<a href="05_keywordconversion.html">Previous</a> •
|
161
|
+
<a href="index.html">Up</a> •
|
162
|
+
<a href="07_applicationobjects.html">Next</a>
|
163
|
+
|
164
|
+
<span>© 2006-2008 HAS</span>
|
150
165
|
</div>
|
151
166
|
|
152
|
-
<!--footer-->
|
153
|
-
<p class="footer">© 2006-2008 HAS</p>
|
154
167
|
</body>
|
155
168
|
</html>
|