rb-appscript 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +28 -0
- data/README +51 -31
- data/doc/aem-manual/01_introduction.html +0 -2
- data/doc/aem-manual/02_apioverview.html +13 -9
- data/doc/aem-manual/03_packingandunpackingdata.html +41 -9
- data/doc/aem-manual/04_references.html +42 -40
- data/doc/aem-manual/{05_targettingapplications.html → 05_targetingapplications.html} +4 -6
- data/doc/aem-manual/06_buildingandsendingevents.html +40 -12
- data/doc/aem-manual/07_findapp.html +0 -2
- data/doc/aem-manual/08_examples.html +0 -2
- data/doc/aem-manual/aemreferenceinheritance.gif +0 -0
- data/doc/aem-manual/index.html +1 -3
- data/doc/appscript-manual/01_introduction.html +0 -2
- data/doc/appscript-manual/02_aboutappscripting.html +4 -6
- data/doc/appscript-manual/03_quicktutorial.html +1 -3
- data/doc/appscript-manual/04_gettinghelp.html +20 -7
- data/doc/appscript-manual/05_keywordconversion.html +5 -3
- data/doc/appscript-manual/06_classesandenums.html +32 -8
- data/doc/appscript-manual/07_applicationobjects.html +30 -41
- data/doc/appscript-manual/08_realvsgenericreferences.html +0 -2
- data/doc/appscript-manual/09_referenceforms.html +0 -2
- data/doc/appscript-manual/10_referenceexamples.html +1 -3
- data/doc/appscript-manual/11_applicationcommands.html +29 -2
- data/doc/appscript-manual/12_commandexamples.html +0 -2
- data/doc/appscript-manual/13_performanceissues.html +0 -2
- data/doc/appscript-manual/14_notes.html +0 -19
- data/doc/appscript-manual/index.html +0 -2
- data/doc/index.html +1 -4
- data/doc/mactypes-manual/01_introduction.html +0 -2
- data/doc/mactypes-manual/02_aliasclass.html +0 -10
- data/doc/mactypes-manual/03_fileurlclass.html +1 -11
- data/doc/mactypes-manual/04_unitsclass.html +0 -2
- data/doc/mactypes-manual/index.html +0 -2
- data/doc/osax-manual/01_introduction.html +0 -2
- data/doc/osax-manual/02_interface.html +0 -2
- data/doc/osax-manual/03_examples.html +0 -2
- data/doc/osax-manual/04_notes.html +6 -25
- data/doc/osax-manual/index.html +0 -2
- data/rb-appscript.gemspec +2 -3
- data/sample/AB_export_vcard.rb +0 -0
- data/sample/AB_list_people_with_emails.rb +0 -0
- data/sample/Create_daily_iCal_todos.rb +0 -0
- data/sample/Export_Address_Book_phone_numbers.rb +0 -0
- data/sample/Hello_world.rb +0 -0
- data/sample/List_iTunes_playlist_names.rb +0 -0
- data/sample/Open_file_in_TextEdit.rb +0 -0
- data/sample/Organize_Mail_messages.rb +0 -0
- data/sample/TextEdit_demo.rb +0 -0
- data/sample/iTunes_top40_to_html.rb +0 -0
- data/src/SendThreadSafe.c +0 -0
- data/src/SendThreadSafe.h +0 -0
- data/src/lib/_aem/aemreference.rb +5 -7
- data/src/lib/_aem/codecs.rb +47 -24
- data/src/lib/_aem/connect.rb +29 -8
- data/src/lib/_aem/encodingsupport.rb +77 -0
- data/src/lib/_aem/findapp.rb +0 -2
- data/src/lib/_aem/mactypes.rb +0 -2
- data/src/lib/_aem/send.rb +6 -8
- data/src/lib/_aem/typewrappers.rb +0 -2
- data/src/lib/_appscript/defaultterminology.rb +0 -2
- data/src/lib/_appscript/referencerenderer.rb +1 -3
- data/src/lib/_appscript/reservedkeywords.rb +0 -2
- data/src/lib/_appscript/safeobject.rb +58 -9
- data/src/lib/_appscript/terminology.rb +63 -46
- data/src/lib/aem.rb +3 -4
- data/src/lib/appscript.rb +12 -13
- data/src/lib/osax.rb +436 -9
- data/src/rbae.c +126 -103
- data/test/test_aemreference.rb +0 -0
- data/test/test_appscriptcommands.rb +15 -1
- data/test/test_appscriptreference.rb +0 -0
- data/test/test_codecs.rb +10 -4
- data/test/test_findapp.rb +0 -0
- data/test/test_mactypes.rb +0 -0
- data/test/test_osax.rb +0 -0
- data/test/testall.sh +0 -0
- metadata +24 -24
- data/LICENSE +0 -70
- data/TODO +0 -19
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
<!-- top navigation -->
|
16
16
|
<div class="navbar">
|
17
|
-
<a href="
|
17
|
+
<a href="05_targetingapplications.html">Previous</a> •
|
18
18
|
<a href="index.html">Up</a> •
|
19
19
|
<a href="07_findapp.html">Next</a>
|
20
20
|
|
@@ -168,33 +168,61 @@ KAE::KAECanSwitchLayer</code></pre>
|
|
168
168
|
<pre><code>KAE::KAutoGenerateReturnID</code></pre>
|
169
169
|
|
170
170
|
|
171
|
-
<h3>
|
171
|
+
<h3>Exception classes</h3>
|
172
172
|
|
173
|
-
<
|
173
|
+
<h4>The <code>EventError</code> class</h4>
|
174
174
|
|
175
|
-
<
|
175
|
+
<p>The <code>EventError</code> class is raised by <code>Event#send</code> and represents an error raised by the target application or Apple Event Manager when sending an event.</p>
|
176
176
|
|
177
|
-
|
177
|
+
<pre><code>EventError < RuntimeError
|
178
178
|
|
179
|
+
Methods:
|
180
|
+
|
179
181
|
number
|
180
|
-
Result: integer -- error number
|
182
|
+
Result: integer -- Mac OS error number
|
181
183
|
|
182
184
|
message
|
183
|
-
Result: string | nil --
|
184
|
-
|
185
|
-
|
185
|
+
Result: string | nil -- application-supplied/generic
|
186
|
+
error description
|
187
|
+
|
188
|
+
offending_object
|
189
|
+
Result: anything | nil -- object that caused the error,
|
190
|
+
if given by application
|
191
|
+
|
192
|
+
expected_type
|
193
|
+
Result: anything | nil -- object that caused a coercion
|
194
|
+
error, if given by application
|
195
|
+
|
196
|
+
partial_result
|
197
|
+
Result: anything | nil -- part of return value constructed
|
198
|
+
before error occurred, if given by application
|
199
|
+
|
200
|
+
to_i -- Mac OS error number
|
201
|
+
|
202
|
+
to_s -- formatted description of error</code></pre>
|
203
|
+
|
204
|
+
|
205
|
+
<h4><code>AE::MacOSError</code></h4>
|
206
|
+
|
207
|
+
<p>The <code>AE::MacOSError</code> exception is raised by the low-level <code>AE</code> extension and represents an error raised by the Apple Event Manager. The <code>AEM</code> API usually traps these low-level errors and throws more descriptive errors in their place (e.g. <code>AEM::EventError</code>).</p>
|
208
|
+
|
209
|
+
<pre><code>MacOSError < StandardError
|
186
210
|
|
211
|
+
Methods:
|
212
|
+
number
|
213
|
+
Result: integer -- the Mac OS error number
|
214
|
+
|
215
|
+
description
|
216
|
+
Result: string -- short generic error description</code></pre>
|
187
217
|
|
188
218
|
</div>
|
189
219
|
|
190
220
|
<!-- bottom navigation -->
|
191
221
|
|
192
222
|
<div class="footer">
|
193
|
-
<a href="
|
223
|
+
<a href="05_targetingapplications.html">Previous</a> •
|
194
224
|
<a href="index.html">Up</a> •
|
195
225
|
<a href="07_findapp.html">Next</a>
|
196
|
-
|
197
|
-
<span>© 2006-2008 HAS</span>
|
198
226
|
</div>
|
199
227
|
|
200
228
|
</body>
|
@@ -57,8 +57,6 @@ by_creator(creator) -- Find the application with the given creator type.
|
|
57
57
|
<a href="06_buildingandsendingevents.html">Previous</a> •
|
58
58
|
<a href="index.html">Up</a> •
|
59
59
|
<a href="08_examples.html">Next</a>
|
60
|
-
|
61
|
-
<span>© 2006-2008 HAS</span>
|
62
60
|
</div>
|
63
61
|
|
64
62
|
</body>
|
Binary file
|
data/doc/aem-manual/index.html
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
<li><a href="02_apioverview.html">API overview</a></li>
|
37
37
|
<li><a href="03_packingandunpackingdata.html">Packing and unpacking data</a></li>
|
38
38
|
<li><a href="04_references.html">References</a></li>
|
39
|
-
<li><a href="
|
39
|
+
<li><a href="05_targetingapplications.html">Targeting applications</a></li>
|
40
40
|
<li><a href="06_buildingandsendingevents.html">Building and sending events</a></li>
|
41
41
|
<li><a href="07_findapp.html">Locating applications</a></li>
|
42
42
|
<li><a href="08_examples.html">Examples</a></li>
|
@@ -50,8 +50,6 @@
|
|
50
50
|
<a href="../index.html">Previous</a> •
|
51
51
|
<a href="../index.html">Up</a> •
|
52
52
|
<a href="01_introduction.html">Next</a>
|
53
|
-
|
54
|
-
<span>© 2006-2008 HAS</span>
|
55
53
|
</div>
|
56
54
|
|
57
55
|
</body>
|
@@ -191,14 +191,14 @@ app('TextEdit').documents[1].text.paragraphs</code></pre>
|
|
191
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>
|
192
192
|
|
193
193
|
<dl>
|
194
|
-
<dt><code>
|
194
|
+
<dt><code>AE</code></dt><dd>A low-level, mostly procedural Ruby wrapper around Mac OS X's Apple Event Manager API.</dd>
|
195
195
|
|
196
|
-
<dt><code>
|
196
|
+
<dt><code>AEM</code></dt><dd>A mid-level wrapper around <code>AE</code>, providing an object-oriented API for building relational AEOM queries and dispatching events.</dd>
|
197
197
|
|
198
|
-
<dt><code>
|
198
|
+
<dt><code>Appscript</code></dt><dd>A high-level wrapper around <code>AEM</code>, providing automatic translation between human-readable application terminology and corresponding four-letter codes, and representing relational AEOM queries in an OO-like syntax for ease of use.</dd>
|
199
199
|
</dl>
|
200
200
|
|
201
|
-
<p>The <code>
|
201
|
+
<p>The <code>AE</code> extension primarily serves as a foundation for higher-level libraries to build on; it's rarely used directly as it takes a significant amount of code to perform all but the most trivial of tasks. The <code>AEM</code> module is largely intended for use by higher-level libraries and developers, though may also be used by end-users in cases where an application lacks terminology, or bugs within its terminology prevent its use by appscript. The <code>Appscript</code> module is intended for use by both developers and end-users, though developers may prefer aem for certain tasks as appscript doesn't expose all aspects of the aem API (such as the ability to do asynchronous messaging) and terminology translation imposes additional overheads and dependencies on client code.</p>
|
202
202
|
|
203
203
|
<p>For example, to set the size of the first character of every non-empty paragraph in every document of TextEdit to 24 pt:</p>
|
204
204
|
|
@@ -241,8 +241,6 @@ app('TextEdit').documents[1].text.paragraphs</code></pre>
|
|
241
241
|
<a href="01_introduction.html">Previous</a> •
|
242
242
|
<a href="index.html">Up</a> •
|
243
243
|
<a href="03_quicktutorial.html">Next</a>
|
244
|
-
|
245
|
-
<span>© 2006-2008 HAS</span>
|
246
244
|
</div>
|
247
245
|
|
248
246
|
</body>
|
@@ -53,7 +53,7 @@ irb(main):001:0></code></pre>
|
|
53
53
|
irb> include Appscript
|
54
54
|
=> Object</code></pre>
|
55
55
|
|
56
|
-
<p>Once appscript is imported,
|
56
|
+
<p>Once appscript is imported, create new <code>app</code> object, identifying the application to be manipulated, and assign it to a variable, <code>te</code>, for easy reuse:</p>
|
57
57
|
|
58
58
|
<pre><code>irb> te = app('TextEdit')
|
59
59
|
=> app("/Applications/TextEdit.app")</code></pre>
|
@@ -161,8 +161,6 @@ irb> te.documents.text.get
|
|
161
161
|
<a href="02_aboutappscripting.html">Previous</a> •
|
162
162
|
<a href="index.html">Up</a> •
|
163
163
|
<a href="04_gettinghelp.html">Next</a>
|
164
|
-
|
165
|
-
<span>© 2006-2008 HAS</span>
|
166
164
|
</div>
|
167
165
|
|
168
166
|
</body>
|
@@ -31,7 +31,7 @@
|
|
31
31
|
|
32
32
|
<h2>4. Getting Help</h2>
|
33
33
|
|
34
|
-
<p>When developing appscript-based scripts, there are several ways to get information about applications' scripting interfaces: the ASDictionary application
|
34
|
+
<p>When developing appscript-based scripts, there are several ways to get information about applications' scripting interfaces: the ASDictionary application, appscript's powerful built-in <code>help</code> method, and introspection.</p>
|
35
35
|
|
36
36
|
|
37
37
|
|
@@ -39,8 +39,6 @@
|
|
39
39
|
|
40
40
|
<p>ASDictionary, available from the appscript website's <a href="http://appscript.sourceforge.net/tools.html">Tools 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>
|
41
41
|
|
42
|
-
<p>In addition, the <code>asdict</code> tool bundled with ASDictionary can be used to export application dictionaries in HTML format, or browse them interactively from the command line. See ASDictionary's documentation for more information.</p>
|
43
|
-
|
44
42
|
|
45
43
|
|
46
44
|
<h3>Built-in <code>help</code> method</h3>
|
@@ -139,6 +137,25 @@ p te.parameters('make')
|
|
139
137
|
# ["at", "new", "with_data", "with_properties"]</code></pre>
|
140
138
|
|
141
139
|
|
140
|
+
|
141
|
+
<h3>ASTranslate</h3>
|
142
|
+
|
143
|
+
<p>ASTranslate, available from the appscript website's <a href="http://appscript.sourceforge.net/tools.html">tools page</a>, provides a simple tool for translating application commands from AppleScript to Ruby syntax - useful when help is needed in converting existing AppleScript code to Ruby. For example, the following AppleScript selects every file in the Home folder:</p>
|
144
|
+
|
145
|
+
<pre><code>tell application "Finder"
|
146
|
+
select (every file of home whose name extension is in {"htm", "html"})
|
147
|
+
end tell</code></pre>
|
148
|
+
|
149
|
+
<p>To obtain the appscript equivalent, paste this script into ASTranslate and select <code>Execute</code> from the <code>Document</code> menu. ASTranslate will intercept any Apple events sent by AppleScript and display them appscript format:</p>
|
150
|
+
|
151
|
+
<pre><code>app("Finder").home.files[its.name_extension.is_in(["htm", "html"])].select
|
152
|
+
|
153
|
+
OK</code></pre>
|
154
|
+
|
155
|
+
<p>See ASTranslate's documentation for more information.</p>
|
156
|
+
|
157
|
+
|
158
|
+
|
142
159
|
<h3>Notes</h3>
|
143
160
|
|
144
161
|
<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>
|
@@ -153,8 +170,6 @@ p te.parameters('make')
|
|
153
170
|
|
154
171
|
<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>
|
155
172
|
|
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
173
|
<li>The <a href="http://appscript.sourceforge.net">appscript website</a> has links to mailing lists and other general resources.</li>
|
159
174
|
</ul>
|
160
175
|
|
@@ -167,8 +182,6 @@ p te.parameters('make')
|
|
167
182
|
<a href="03_quicktutorial.html">Previous</a> •
|
168
183
|
<a href="index.html">Up</a> •
|
169
184
|
<a href="05_keywordconversion.html">Next</a>
|
170
|
-
|
171
|
-
<span>© 2006-2008 HAS</span>
|
172
185
|
</div>
|
173
186
|
|
174
187
|
</body>
|
@@ -86,18 +86,20 @@ hash to_s
|
|
86
86
|
help type
|
87
87
|
ID untaint
|
88
88
|
id wait_reply</code></pre>
|
89
|
-
</div>
|
90
89
|
</li>
|
90
|
+
|
91
|
+
<li>Appscript provides default terminology for standard type classes such as <code>integer</code> and <code>unicode_text</code>, and standard commands such as <code>open</code> and <code>quit</code>. If an application-defined name matches a built-in name but has a different Apple event code, appscript will append an underscore to the application-defined name.</li>
|
91
92
|
</ul>
|
92
93
|
|
94
|
+
<p class="hilitebox">You can use ASDictionary or appscript's built-in <code>help</code> method to export or view application terminology in appscript format. See the <a href="04_gettinghelp.html">Getting Help</a> chapter for more information.</p>
|
95
|
+
</div>
|
96
|
+
|
93
97
|
<!-- bottom navigation -->
|
94
98
|
|
95
99
|
<div class="footer">
|
96
100
|
<a href="04_gettinghelp.html">Previous</a> •
|
97
101
|
<a href="index.html">Up</a> •
|
98
102
|
<a href="06_classesandenums.html">Next</a>
|
99
|
-
|
100
|
-
<span>© 2006-2008 HAS</span>
|
101
103
|
</div>
|
102
104
|
|
103
105
|
</body>
|
@@ -50,12 +50,15 @@
|
|
50
50
|
:no
|
51
51
|
:ask</code></pre>
|
52
52
|
|
53
|
-
<p>Occasionally an application dictionary defines a type or enumerator without providing it with a corresponding name name. In these cases, the value will be represented as a raw <code>AEM::AEType</code> or <code>AEM::AEEnum</code> object instead of a symbol, e.g
|
53
|
+
<p>Occasionally an application dictionary defines a type or enumerator without providing it with a corresponding name name. In these cases, the value will be represented as a raw <code>AEM::AEType</code> or <code>AEM::AEEnum</code> object instead of a symbol, e.g.:</p>
|
54
54
|
|
55
55
|
<pre><code>AEM::AEType.new('abcd')
|
56
56
|
|
57
57
|
AEM::AEEnum.new('xyz ')</code></pre>
|
58
58
|
|
59
|
+
<p>See the aem manual for more information on these lower-level objects, should you need to use them.</p>
|
60
|
+
|
61
|
+
|
59
62
|
<h3>Common AE types</h3>
|
60
63
|
|
61
64
|
<table width="100%" summary="AE-Ruby type mappings">
|
@@ -98,23 +101,46 @@ AEM::AEEnum.new('xyz ')</code></pre>
|
|
98
101
|
<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>
|
99
102
|
|
100
103
|
|
101
|
-
<h4>Strings</h4>
|
104
|
+
<h4>Strings (Ruby 1.8)</h4>
|
102
105
|
|
103
|
-
<p>Because Ruby lacks
|
106
|
+
<p>Because Ruby 1.8 lacks native Unicode support, appscript unpacks all text-related AE types (<code>typeChar</code>, <code>typeUnicodeText</code>, etc.) as String instances containing UTF8-encoded data.</p>
|
104
107
|
|
105
|
-
<p>Appscript packs UTF8-encoded
|
108
|
+
<p>Appscript packs String instances containing UTF8-encoded data as the <code>typeUnicodeText</code> AE type. If the string does not contain valid UTF-8 data, a TypeError will be raised.</p>
|
106
109
|
|
107
110
|
<div class="hilitebox">
|
108
|
-
<p>You can enable a degree of
|
111
|
+
<p>You can enable a degree of UTF-8 support in Ruby's <code>String</code> class via the Jcode module (included in Ruby's standard library). To use Jcode, add the following lines to the start of your Ruby scripts, irb sessions, etc.:</p>
|
109
112
|
<pre><code>require "jcode"
|
110
113
|
$KCODE = "UTF8"</code></pre>
|
111
114
|
|
112
115
|
<p>This will improve the display of non-ASCII characters in irb, amongst other things.</p>
|
113
116
|
|
114
117
|
</div>
|
118
|
+
|
115
119
|
<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>
|
116
120
|
|
117
121
|
|
122
|
+
<h4>Strings (Ruby 1.9+)</h4>
|
123
|
+
|
124
|
+
<p>Each String instance in Ruby 1.9+ contains an <code>Encoding</code> instance that identifies the character set used. By default, appscript unpacks a text descriptors as a String instance containing UTF-8 encoded data and a UTF-8 Encoding, and encodes a string as UTF-8 prior to packing its data into a text descriptor. To disable this behavior for individual <code>Application</code> instances:</p>
|
125
|
+
|
126
|
+
<pre><code>some_app = Appscript.app('SomeApp')
|
127
|
+
some_app.AS_app_data.use_ascii_8bit
|
128
|
+
# Send commands here...</code></pre>
|
129
|
+
|
130
|
+
<p>Once invoked, Strings will be treated as UTF-8 encoded data with ASCII-8BIT Encoding; this is equivalent to the Ruby 1.8 behavior.</p>
|
131
|
+
|
132
|
+
|
133
|
+
<h4>Dates and Times</h4>
|
134
|
+
|
135
|
+
<p>Appscript packs Ruby <code>Time</code>, <code>Date</code> and <code>DateTime</code> instances as <code>typeLongDateTime</code> descriptors. (Note that AE dates does not include locale information.)</p>
|
136
|
+
|
137
|
+
<p>By default, <code>typeLongDateTime</code> descriptors are unpacked as Ruby <code>Time</code> instances. This is sufficient for most purposes; however, where the AEDesc contains a date value below or above the range supported by Ruby's <code>Time</code> class, an error will occur. To unpack dates as <code>DateTime</code> instances for individual <code>Application</code> instances:</p>
|
138
|
+
|
139
|
+
<pre><code>some_app = Appscript.app('SomeApp')
|
140
|
+
some_app.AS_app_data.use_datetime
|
141
|
+
# Send commands here...</code></pre>
|
142
|
+
|
143
|
+
|
118
144
|
<h4>Filesystem references</h4>
|
119
145
|
|
120
146
|
<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>
|
@@ -139,7 +165,7 @@ $KCODE = "UTF8"</code></pre>
|
|
139
165
|
|
140
166
|
<h4>Types and enumerators</h4>
|
141
167
|
|
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.</
|
168
|
+
<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.</p>
|
143
169
|
|
144
170
|
|
145
171
|
<h4>Unit types</h4>
|
@@ -160,8 +186,6 @@ $KCODE = "UTF8"</code></pre>
|
|
160
186
|
<a href="05_keywordconversion.html">Previous</a> •
|
161
187
|
<a href="index.html">Up</a> •
|
162
188
|
<a href="07_applicationobjects.html">Next</a>
|
163
|
-
|
164
|
-
<span>© 2006-2008 HAS</span>
|
165
189
|
</div>
|
166
190
|
|
167
191
|
</body>
|
@@ -34,47 +34,34 @@
|
|
34
34
|
<h3>Creating application objects</h3>
|
35
35
|
|
36
36
|
|
37
|
-
<p>Before you can communicate with a scriptable application you must
|
37
|
+
<p>Before you can communicate with a scriptable application you must create an <code>Application</code> object, for example:</p>
|
38
38
|
|
39
|
-
<pre><code>app.
|
39
|
+
<pre><code>textedit = app.by_id('com.apple.textedit')</code></pre>
|
40
40
|
|
41
|
-
app.by_id(id) # bundle ID for a local application
|
42
41
|
|
43
|
-
app
|
44
|
-
|
45
|
-
app.by_pid(pid) # Unix process id for a local process
|
46
|
-
|
47
|
-
app.by_url(url) # eppc URL for a remote process
|
48
|
-
|
49
|
-
app.by_aem_app(aem_app) # AEM::Application instance
|
50
|
-
|
51
|
-
app.current # the host process</code></pre>
|
52
|
-
|
53
|
-
<p>For convenience, the most commonly used form, <code>app.by_name(name)</code>, can be shortened to:</p>
|
54
|
-
|
55
|
-
<pre><code>app(name)</code></pre>
|
56
|
-
|
57
|
-
|
58
|
-
<p>To target an application you must supply one of the following arguments:</p>
|
42
|
+
<p>To target an application you must call one of the <code>app</code> object's <code>by_*</code> methods with the appropriate argument:</p>
|
59
43
|
|
60
44
|
<dl>
|
61
|
-
<dt><code>name</code></dt>
|
45
|
+
<dt><code>app.by_name(<var>name</var>)</code> / <code>app(<var>name</var>)</code></dt>
|
62
46
|
<dd>The application's filename or POSIX path, e.g. <code>'TextEdit'</code>, <code>'TextEdit.app'</code>, <code>'/Applications/TextEdit.app'</code>. Where a filename is provided, appscript uses LaunchServices to locate the application. An <code>.app</code> suffix is optional. e.g. Given the name <code>'TextEdit'</code>, appscript first searches for an application with that exact filename; if none is found, it automatically adds an <code>.app</code> suffix (<code>'TextEdit.app'</code>) and tries again.</dd>
|
63
47
|
|
64
|
-
<dt><code>id</code></dt>
|
48
|
+
<dt><code>app.by_id(<var>id</var>)</code></dt>
|
65
49
|
<dd>The application's bundle id, e.g. <code>'com.apple.textedit'</code>. Cocoa applications often have unique bundle ids.</dd>
|
66
50
|
|
67
|
-
<dt><code>creator</code></dt>
|
51
|
+
<dt><code>app.by_creator(<var>creator</var>)</code></dt>
|
68
52
|
<dd>A four-character string containing the application's creator type, e.g. <code>'ttxt'</code>. Older Carbon-based applications and some Cocoa-based applications have unique creator types.</dd>
|
69
53
|
|
70
|
-
<dt><code>pid</code></dt>
|
54
|
+
<dt><code>app.by_pid(<var>pid</var>)</code></dt>
|
71
55
|
<dd>A valid Unix process id, e.g. <code>5687</code>.</dd>
|
72
56
|
|
73
|
-
<dt><code>url</code></dt>
|
57
|
+
<dt><code>app.by_url(<var>url</var>)</code></dt>
|
74
58
|
<dd>A URL of form <code>eppc://[user[:password]@host/Application%20Name[?[uid=#]&[pid=#]</code>, e.g. <code>eppc://johnsmith:foobar@office-mac.local/TextEdit?uid=501</code>. The host name/IP address and the process name (case-sensitive) are required. The username and password are optional: if omitted, the OS will obtain this information from the user's keychain or display a dialog asking the user to input one or both values. The user id and process id are also optional; if the process id is given, the process name will be ignored.</dd>
|
75
59
|
|
76
|
-
<dt><code>aem_app</code></dt>
|
60
|
+
<dt><code>app.by_aem_app(<var>aem_app</var>)</code></dt>
|
77
61
|
<dd>An <code>AEM::Application</code> instance.</dd>
|
62
|
+
|
63
|
+
<dt><code>app.current</code></dt>
|
64
|
+
<dd>The host application.</dd>
|
78
65
|
</dl>
|
79
66
|
|
80
67
|
|
@@ -102,25 +89,29 @@ itunes = app.by_url('eppc://Jan%20Smith@G4.local/iTunes')</code></pre>
|
|
102
89
|
|
103
90
|
<p>All applications should respond to the following commands:</p>
|
104
91
|
|
105
|
-
<pre><code>run -- Run an application.
|
106
|
-
|
92
|
+
<pre><code>run -- Run an application. Most applications will open an empty,
|
93
|
+
untitled window.
|
107
94
|
|
108
|
-
launch -- Launch an application without sending it a 'run' event.
|
109
|
-
|
95
|
+
launch -- Launch an application without sending it a 'run' event.
|
96
|
+
Applications that normally open a new, empty document
|
97
|
+
upon launch won't. [1]
|
110
98
|
|
111
99
|
activate -- Bring the application to the front.
|
112
100
|
|
113
|
-
reopen -- Reactivate a running application.
|
114
|
-
|
101
|
+
reopen -- Reactivate a running application. Some applications
|
102
|
+
will open a new untitled window if no window is open.
|
115
103
|
|
116
|
-
open(
|
117
|
-
|
104
|
+
open(<var>value</var>) -- Open the specified object(s).
|
105
|
+
anything -- list of objects to open, typically a list of
|
106
|
+
MacTypes::Alias
|
118
107
|
|
119
|
-
print(
|
120
|
-
|
108
|
+
print(<var>value</var>) -- Print the specified object(s).
|
109
|
+
anything -- list of objects to print, typically a list of
|
110
|
+
MacTypes::Alias
|
121
111
|
|
122
|
-
quit(saving) -- Quit an application.
|
123
|
-
saving : :yes | :ask | :no -- specifies whether to save
|
112
|
+
quit(saving => <var>value</var>) -- Quit an application.
|
113
|
+
saving : :yes | :ask | :no -- specifies whether to save
|
114
|
+
currently open documents
|
124
115
|
</code></pre>
|
125
116
|
|
126
117
|
<p><small>[1] The <code>launch</code> command should be used before constructing references or sending other commands, otherwise appscript will run the application normally.</small></p>
|
@@ -129,11 +120,11 @@ quit(saving) -- Quit an application.
|
|
129
120
|
|
130
121
|
<p>Appscript also defines <code>get</code> and <code>set</code> commands for any scriptable application that doesn't supply its own definitions:</p>
|
131
122
|
|
132
|
-
<pre><code>get(
|
123
|
+
<pre><code>get(<var>value</var>) -- Get the data for an object.
|
133
124
|
reference -- the object for the command
|
134
125
|
Result: anything -- the reply for the command
|
135
126
|
|
136
|
-
set(
|
127
|
+
set(<var>value</var>, :to => <var>value</var>) -- Set an object's data.
|
137
128
|
reference -- the object for the command
|
138
129
|
to : anything -- The new value.</code></pre>
|
139
130
|
|
@@ -214,8 +205,6 @@ te.launch
|
|
214
205
|
<a href="06_classesandenums.html">Previous</a> •
|
215
206
|
<a href="index.html">Up</a> •
|
216
207
|
<a href="08_realvsgenericreferences.html">Next</a>
|
217
|
-
|
218
|
-
<span>© 2006-2008 HAS</span>
|
219
208
|
</div>
|
220
209
|
|
221
210
|
</body>
|