rb-appscript 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CHANGES +243 -0
  2. data/LICENSE +1 -0
  3. data/README +42 -0
  4. data/TODO +31 -0
  5. data/doc/aem-manual/01_introduction.html +48 -0
  6. data/doc/aem-manual/02_apioverview.html +89 -0
  7. data/doc/aem-manual/03_packingandunpackingdata.html +98 -0
  8. data/doc/aem-manual/04_references.html +401 -0
  9. data/doc/aem-manual/05_targettingapplications.html +133 -0
  10. data/doc/aem-manual/06_buildingandsendingevents.html +175 -0
  11. data/doc/aem-manual/07_findapp.html +54 -0
  12. data/doc/aem-manual/08_examples.html +85 -0
  13. data/doc/aem-manual/09_notes.html +41 -0
  14. data/doc/aem-manual/aemreferenceinheritance.gif +0 -0
  15. data/doc/aem-manual/full.css +21 -0
  16. data/doc/aem-manual/index.html +43 -0
  17. data/doc/appscript-manual/01_introduction.html +82 -0
  18. data/doc/appscript-manual/02_aboutappscripting.html +244 -0
  19. data/doc/appscript-manual/03_quicktutorial.html +154 -0
  20. data/doc/appscript-manual/04_gettinghelp.html +101 -0
  21. data/doc/appscript-manual/05_keywordconversion.html +91 -0
  22. data/doc/appscript-manual/06_classesandenums.html +174 -0
  23. data/doc/appscript-manual/07_applicationobjects.html +181 -0
  24. data/doc/appscript-manual/08_realvsgenericreferences.html +86 -0
  25. data/doc/appscript-manual/09_referenceforms.html +232 -0
  26. data/doc/appscript-manual/10_referenceexamples.html +142 -0
  27. data/doc/appscript-manual/11_applicationcommands.html +204 -0
  28. data/doc/appscript-manual/12_commandexamples.html +129 -0
  29. data/doc/appscript-manual/13_performanceissues.html +115 -0
  30. data/doc/appscript-manual/14_problemapps.html +193 -0
  31. data/doc/appscript-manual/15_notes.html +84 -0
  32. data/doc/appscript-manual/application_architecture.gif +0 -0
  33. data/doc/appscript-manual/application_architecture2.gif +0 -0
  34. data/doc/appscript-manual/finder_to_textedit_event.gif +0 -0
  35. data/doc/appscript-manual/full.css +21 -0
  36. data/doc/appscript-manual/index.html +49 -0
  37. data/doc/appscript-manual/relationships_example.gif +0 -0
  38. data/doc/appscript-manual/ruby_to_itunes_event.gif +0 -0
  39. data/doc/index.html +30 -0
  40. data/doc/mactypes-manual/index.html +216 -0
  41. data/doc/osax-manual/index.html +169 -0
  42. data/extconf.rb +54 -0
  43. data/misc/adobeunittypes.rb +14 -0
  44. data/misc/dump.rb +72 -0
  45. data/rb-appscript.gemspec +20 -0
  46. data/sample/AB_list_people_with_emails.rb +8 -0
  47. data/sample/Create_daily_iCal_todos.rb +72 -0
  48. data/sample/Hello_world.rb +9 -0
  49. data/sample/List_iTunes_playlist_names.rb +7 -0
  50. data/sample/Make_Mail_message.rb +29 -0
  51. data/sample/Open_file_in_TextEdit.rb +9 -0
  52. data/sample/Organize_Mail_messages.rb +57 -0
  53. data/sample/Print_folder_tree.rb +12 -0
  54. data/sample/Select_all_HTML_files.rb +8 -0
  55. data/sample/Set_iChat_status.rb +20 -0
  56. data/sample/Simple_Finder_GUI_Scripting.rb +14 -0
  57. data/sample/Stagger_Finder_windows.rb +21 -0
  58. data/sample/TextEdit_demo.rb +126 -0
  59. data/sample/iTunes_top40_to_html.rb +64 -0
  60. data/src/lib/_aem/aemreference.rb +1006 -0
  61. data/src/lib/_aem/codecs.rb +617 -0
  62. data/src/lib/_aem/connect.rb +100 -0
  63. data/src/lib/_aem/findapp.rb +83 -0
  64. data/src/lib/_aem/mactypes.rb +228 -0
  65. data/src/lib/_aem/send.rb +257 -0
  66. data/src/lib/_aem/typewrappers.rb +57 -0
  67. data/src/lib/_appscript/defaultterminology.rb +245 -0
  68. data/src/lib/_appscript/referencerenderer.rb +132 -0
  69. data/src/lib/_appscript/reservedkeywords.rb +107 -0
  70. data/src/lib/_appscript/terminology.rb +314 -0
  71. data/src/lib/aem.rb +216 -0
  72. data/src/lib/appscript.rb +830 -0
  73. data/src/lib/kae.rb +1484 -0
  74. data/src/lib/osax.rb +171 -0
  75. data/src/rbae.c +766 -0
  76. data/test/README +1 -0
  77. data/test/test_aemreference.rb +112 -0
  78. data/test/test_appscriptreference.rb +102 -0
  79. data/test/test_codecs.rb +159 -0
  80. data/test/test_findapp.rb +24 -0
  81. data/test/test_mactypes.rb +67 -0
  82. data/test/testall.sh +9 -0
  83. metadata +143 -0
@@ -0,0 +1,232 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+
5
+ <title>appscript | 9. Reference Forms</title>
6
+
7
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
8
+ <style type="text/css" media="all"><!--@import url(full.css);--></style>
9
+
10
+ </head>
11
+ <body>
12
+
13
+ <h1>9. Reference Forms</h1>
14
+
15
+ <!-- top navigation -->
16
+ <div class="navbar">
17
+ <a href="08_realvsgenericreferences.html">Previous</a> | <a href="index.html">Up</a> | <a href="10_referenceexamples.html">Next</a>
18
+
19
+ </div>
20
+
21
+ <!-- content -->
22
+ <div id="content">
23
+ <h2>Property Reference</h2>
24
+
25
+ <p>A property either contains a simple value or represents a one-to-one relationship between two application objects. Properties either describe the application object (its name, class, size, color, preferences, etc.) or provide a convenient reference to other object(s) of interest to users (e.g. home, current_track).</p>
26
+
27
+ <p>Syntax:</p>
28
+ <pre><code>reference.property</code></pre>
29
+
30
+ <p>Examples:</p>
31
+ <pre><code>textedit.<em>name</em>
32
+ textedit.documents[1].<em>text</em>
33
+ finder.<em>home</em>.files.<em>name</em></code></pre>
34
+
35
+
36
+
37
+ <h2>Element References</h2>
38
+
39
+ <p>Elements represent a one-to-many relationship between application objects. Elements usually reflect the containment structure of the application object model and generally provide multiple ways of referencing some or all of those objects (e.g. characters/words/paragraphs of documents by index/relative-position/range/filter).</p>
40
+
41
+ <h3>All Elements</h3>
42
+
43
+ <p>Syntax:</p>
44
+ <pre><code>reference.elements</code></pre>
45
+
46
+ <p>Examples:</p>
47
+ <pre><code>finder.home.<em>folders</em>
48
+ textedit.<em>windows</em>
49
+ textedit.<em>documents</em>.<em>paragraphs</em>.<em>words</em></code></pre>
50
+
51
+
52
+ <h3>by Name</h3>
53
+
54
+ <p>Syntax:</p>
55
+ <pre><code>elements[specifier]
56
+ specifier : String -- name of object (as matches its 'name' property)</code></pre>
57
+
58
+ <p>Examples:</p>
59
+ <pre><code>disks['Macintosh HD']
60
+ files['index.html']</code></pre>
61
+
62
+ <p class="hilitebox">Note: applications usually treat object names as case-insensitive. Where multiple element have the same name, a by-name reference only identifies the first element found with that name. (Tip: to identify <em>all</em> elements with a particular name, use a by-filter reference instead.)</p>
63
+
64
+
65
+ <h3>by Index</h3>
66
+
67
+ <p>Syntax:</p>
68
+ <pre><code>elements[specifier]
69
+ specifier : Fixnum | Bignum -- index of object</code></pre>
70
+
71
+ <p>Examples:</p>
72
+ <pre><code>words[3]
73
+ items[-1]</code></pre>
74
+
75
+ <p class="hilitebox">Note: elements are <em>one-indexed</em> (AEM-style indexing), not zero-indexed (Ruby-style indexing).</p>
76
+
77
+
78
+ <h3>by ID</h3>
79
+
80
+ <p>Syntax:</p>
81
+ <pre><code>elements.ID(specifier)
82
+ specifier : anything -- object's id</code></pre>
83
+
84
+ <p>Examples:</p>
85
+ <pre><code>windows.ID(4321)</code></pre>
86
+
87
+
88
+ <h3>by Absolute Position</h3>
89
+
90
+ <p>Syntax:</p>
91
+ <pre><code>elements.first -- first element
92
+ elements.middle -- middle element
93
+ elements.last -- last element
94
+ elements.any -- random element</code></pre>
95
+
96
+ <p>Examples:</p>
97
+ <pre><code>documents.first
98
+ paragraphs.last
99
+ files.any</code></pre>
100
+
101
+
102
+ <h3>by Relative Position</h3>
103
+
104
+ <p>Syntax:</p>
105
+ <pre><code>elements[specifier].previous(class) -- nearest element of a given class to appear
106
+ before the specified element
107
+ elements[specifier].next(class) -- nearest element of a given class to appear
108
+ after the specified element
109
+ class : Symbol -- class of element (see <a href="4_classesandenums.html">Classes and Enumerated Types</a>)</code></pre>
110
+
111
+ <p>Examples:</p>
112
+ <pre><code>words[3].next(:word)
113
+ paragraphs[-1].previous(:character)</code></pre>
114
+
115
+
116
+ <h3>by Range</h3>
117
+
118
+ <p>Range references select all elements between and including two references indicating the start and end of the range. The start and end references are normally declared relative to the container of the elements being selected. Appscript defines an object, <code>con</code> (short for 'container'), to indicate this container; for example, to indicate the third paragraph of the currrent container object:</p>
119
+
120
+ <pre><code>AS.con.paragraphs[3]</code></pre>
121
+
122
+ <p>For convenience, the range reference also allows start and end references to be written in shorthand form where their element class is the same as the elements being selected; thus:</p>
123
+
124
+ <pre><code>ref.paragraphs[AS.con.paragraphs[3], AS.con.paragraphs[-1]]</code></pre>
125
+
126
+ <p>can also be written as:</p>
127
+
128
+ <pre><code>ref.paragraphs[3:-1]</code></pre>
129
+
130
+ <p>Some applications can handle more complex range references. For example, the following will work in Tex-Edit Plus:</p>
131
+
132
+ <pre><code>ref.words[AS.con.characters[5], AS.con.paragraphs[-2]]</code></pre>
133
+
134
+ <p>Syntax:</p>
135
+ <pre><code>elements[start, end]
136
+ start : Fixnum | Bignum | String | Reference -- start of range
137
+ end : Fixnum | Bignum | String | Reference -- end of range</code></pre>
138
+
139
+ <p>Examples:</p>
140
+ <pre><code>folders['Documents', 'Movies']
141
+ documents[1, 3]
142
+ text[AS.con.characters[5], AS.con.words[-2]]</code></pre>
143
+
144
+ <p class="hilitebox">Note: ranges are specified as [start-position, <em>end-position</em>] (AEM-style ranges), not [start-position, <em>length</em>] (Ruby-style ranges).</p>
145
+
146
+ <h3>by Filter</h3>
147
+
148
+ <p>A reference to each element that satisfies one or more conditions specified by a test expression:</p>
149
+
150
+ <pre><code>elements[testExpression]</code></pre>
151
+
152
+ <p>Test expressions consist of the following:</p>
153
+
154
+ <ul>
155
+ <li><p>A reference to each element being tested, represented by appscript's <code>its</code> object. This object supports all valid reference forms, allowing you to construct references to its properties and elements. For example:</p>
156
+
157
+ <pre><code>AS.its
158
+ AS.its.size
159
+ AS.its.words.first</code></pre></li>
160
+
161
+ <li><p>One or more conditional tests, implemented as methods on the reference being tested. Each method takes a test reference or a value as their sole argument.</p>
162
+
163
+ <p>Syntax:</p>
164
+ <pre><code>reference.lt(value) # &lt;
165
+ reference.le(value) # &lt;=
166
+ reference.eq(value) # ==
167
+ reference.ne(value) # !=
168
+ reference.gt(value) # &gt;
169
+ reference.ge(value) # &gt;=
170
+ reference.starts_with(value)
171
+ reference.ends_with(value)
172
+ reference.contains(value)
173
+ reference.is_in(value)
174
+ reference.does_not_start_with(value)
175
+ reference.does_not_end_with(value)
176
+ reference.does_not_contain(value)
177
+ reference.is_not_in(value)
178
+ value : reference or value</code></pre>
179
+
180
+ <p>Examples:</p>
181
+ <pre><code>AS.its.eq('')
182
+ AS.its.size.gt(1024)
183
+ AS.its.words.first.starts_with('A')
184
+ AS.its.characters.first.eq(AS.its.characters.last)</code></pre>
185
+
186
+ <p>Note that Boolean comparison tests can be written as either <code>reference.eq(true)</code> or just <code>reference</code>, e.g. <code>folderRef.files[AS.its.locked]</code></p></li>
187
+
188
+ <li><p>Zero or more logical tests, implemented as properties/methods on conditional tests. The <code>and</code> and <code>or</code> methods take one or more conditional or logic tests as arguments.</p>
189
+
190
+ <p>Syntax:</p>
191
+ <pre><code>test.and(test, ...)
192
+ test.or(test, ...)
193
+ test.not</code></pre>
194
+
195
+ <p>Examples:</p>
196
+ <pre><code>AS.its.eq('').not
197
+ AS.its.size.gt(1024).and(its.size.lt(10240))
198
+ AS.its.words[1].starts_with('A').or(
199
+ its.words[2].contains('ce'),
200
+ its.words[1].eq('Foo'))</code></pre></li>
201
+ </ul>
202
+
203
+
204
+
205
+ <h2>Insertion Location</h2>
206
+
207
+ <p>Insertion locations can be specified at the beginning or end of all elements, or before or after a specified element or element range.</p>
208
+
209
+ <p>Syntax:</p>
210
+ <pre><code>elements.start
211
+ elements.end
212
+ elements[specifier].before
213
+ elements[specifier].after</code></pre>
214
+
215
+ <p>Examples:</p>
216
+ <pre><code>documents.end
217
+ paragraphs[1].before</code></pre>
218
+
219
+
220
+
221
+ </div>
222
+
223
+ <!-- bottom navigation -->
224
+ <div class="navbar">
225
+ <a href="08_realvsgenericreferences.html">Previous</a> | <a href="index.html">Up</a> | <a href="10_referenceexamples.html">Next</a>
226
+
227
+ </div>
228
+
229
+ <!--footer-->
230
+ <p class="footer">&copy; 2006 HAS</p>
231
+ </body>
232
+ </html>
@@ -0,0 +1,142 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+
5
+ <title>appscript | 10. Reference Examples</title>
6
+
7
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
8
+ <style type="text/css" media="all"><!--@import url(full.css);--></style>
9
+
10
+ </head>
11
+ <body>
12
+
13
+ <h1>10. Reference Examples</h1>
14
+
15
+ <!-- top navigation -->
16
+ <div class="navbar">
17
+ <a href="09_referenceforms.html">Previous</a> | <a href="index.html">Up</a> | <a href="11_applicationcommands.html">Next</a>
18
+
19
+ </div>
20
+
21
+ <!-- content -->
22
+ <div id="content">
23
+ <h2>Application objects</h2>
24
+
25
+ <pre><code>require "appscript"
26
+
27
+ # application &quot;Finder&quot;
28
+ AS.app('Finder')
29
+
30
+ # application &quot;Macintosh HD:Applications:TextEdit.app:&quot;
31
+ AS.app('/Applications/TextEdit.app')</code></pre>
32
+
33
+
34
+ <h2>Property References</h2>
35
+
36
+ <pre><code># a reference to startup disk of application &quot;Finder&quot;
37
+ AS.app('Finder').startup_disk
38
+
39
+ # a reference to name of folder 1 of home of application &quot;Finder&quot;
40
+ AS.app('Finder').home.folders[1].name
41
+
42
+ # a reference to name of every item of home of application &quot;Finder&quot;
43
+ AS.app('Finder').home.items.name
44
+
45
+ # a reference to text of every document of application &quot;TextEdit&quot;
46
+ AS.app('TextEdit').documents.text
47
+
48
+ # a reference to color of character 1 of every paragraph of text &not;
49
+ # of document 1 of application &quot;TextEdit&quot;
50
+ AS.app('TextEdit').documents[1].text.paragraphs.characters[1].color</code></pre>
51
+
52
+
53
+ <h2>All Elements References</h2>
54
+
55
+ <pre><code># a reference to disks of application &quot;Finder&quot;
56
+ AS.app('Finder').disks
57
+
58
+ # a reference to every word of every paragraph of text of every document &not;
59
+ # of application &quot;TextEdit&quot;
60
+ AS.app('TextEdit').documents.text.paragraphs.words</code></pre>
61
+
62
+
63
+ <h2>Single Element References</h2>
64
+
65
+ <pre><code># a reference to disk 1 of application &quot;Finder&quot;
66
+ AS.app('Finder').disks[1]
67
+
68
+ # a reference to file &quot;ReadMe.txt&quot; of folder &quot;Documents&quot; of home of application &quot;Finder&quot;
69
+ AS.app('Finder').home.folders['Documents'].files['ReadMe.txt']
70
+
71
+ # a reference to paragraph -1 of text of document 1 of application &quot;TextEdit&quot;
72
+ AS.app('TextEdit').documents[1].text.paragraphs[-1]
73
+
74
+ # a reference to middle paragraph of text of last document of application &quot;TextEdit&quot;
75
+ AS.app('TextEdit').documents.last.text.paragraphs.middle
76
+
77
+ # a reference to any file of home of application &quot;Finder&quot;
78
+ AS.app('Finder').home.files.any</code></pre>
79
+
80
+
81
+ <h2>Relative References</h2>
82
+
83
+ <pre><code># a reference to paragraph before paragraph 6 of text of document 1 of application &quot;TextEdit&quot;
84
+ AS.app('TextEdit').documents[1].text.paragraphs[6].previous(:paragraph)
85
+
86
+ # a reference to paragraph after character 30 of document 1 of application &quot;Tex-Edit Plus&quot;
87
+ AS.app('Tex-Edit Plus').documents[1].characters[30].next(:paragraph)</code></pre>
88
+
89
+
90
+ <h2>Element Range References</h2>
91
+
92
+ <pre><code># a reference to words 1 thru 4 of text of document 1 of application &quot;TextEdit&quot;
93
+ AS.app('TextEdit').documents[1].text.words[1, 4]
94
+
95
+ # a reference to paragraphs 2 thru -1 of text of document 1 of application &quot;TextEdit&quot;
96
+ AS.app('TextEdit').documents[1].text.paragraphs[2, -1]
97
+
98
+ # a reference to folders &quot;Documents&quot; thru &quot;Music&quot; of home of application &quot;Finder&quot;
99
+ AS.app('Finder').home.folders['Documents', 'Music']
100
+
101
+ # a reference to text (word 3) thru (paragraph 7) of document 1 of application &quot;Tex-Edit Plus&quot;
102
+ AS.app('Tex-Edit Plus').documents[1].text[AS.con.words[3], AS.con.paragraphs[7]]</code></pre>
103
+
104
+
105
+ <h2>Filter References</h2>
106
+
107
+ <pre><code># a reference to every document of application &quot;TextEdit&quot; whose text is &quot;\n&quot;
108
+ AS.app('TextEdit').documents[AS.its.text.eq("\n")]
109
+
110
+ # a reference to every paragraph of document 1 of application &quot;Tex-Edit Plus&quot; &not;
111
+ # whose first character is last character
112
+ AS.app('Tex-Edit Plus').documents[1].paragraphs[
113
+ AS.its.characters.first.eq(AS.its.characters.last)]
114
+
115
+ # a reference to every file of folder &quot;Documents&quot; of home of application &quot;Finder&quot; &not;
116
+ # whose name extension is &quot;txt&quot; and size < 10240
117
+ AS.app('Finder').home.folders['Documents'].files[
118
+ AS.its.name_extension.eq('txt').AND(AS.its.size.lt(10240))]</code></pre>
119
+
120
+
121
+ <h2>Insertion Location References</h2>
122
+
123
+ <pre><code># a reference to end of documents of application &quot;TextEdit&quot;
124
+ AS.app('TextEdit').documents.end
125
+
126
+ # a reference to before paragraph 1 of text of document 1 of application &quot;TextEdit&quot;
127
+ AS.app('TextEdit').documents[1].text.paragraphs[1].before</code></pre>
128
+
129
+
130
+
131
+ </div>
132
+
133
+ <!-- bottom navigation -->
134
+ <div class="navbar">
135
+ <a href="09_referenceforms.html">Previous</a> | <a href="index.html">Up</a> | <a href="11_applicationcommands.html">Next</a>
136
+
137
+ </div>
138
+
139
+ <!--footer-->
140
+ <p class="footer">&copy; 2006 HAS</p>
141
+ </body>
142
+ </html>
@@ -0,0 +1,204 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+
5
+ <title>appscript | 11. Application Commands</title>
6
+
7
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
8
+ <style type="text/css" media="all"><!--@import url(full.css);--></style>
9
+
10
+ </head>
11
+ <body>
12
+
13
+ <h1>11. Application Commands</h1>
14
+
15
+ <!-- top navigation -->
16
+ <div class="navbar">
17
+ <a href="10_referenceexamples.html">Previous</a> | <a href="index.html">Up</a> | <a href="12_commandexamples.html">Next</a>
18
+
19
+ </div>
20
+
21
+ <!-- content -->
22
+ <div id="content">
23
+
24
+ <h2>Command syntax</h2>
25
+
26
+ <p>Appscript commands have the following syntax:</p>
27
+
28
+ <pre><code>application.command_name([direct_parameter][, keyword_parameters])</code></pre>
29
+
30
+ <p>Both direct and keyword parameters are optional.</p>
31
+
32
+ <p>Application commands are implemented by the application's top-level <code>application</code> object (represented by an <code>AS::Application</code> instance). For convenience, appscript also makes application commands available as methods on every reference. If a command is called upon a reference rather than an Application object, that reference will be taken as the application's direct parameter (with one or two caveats; see the Special Cases section below).</p>
33
+
34
+ <p>The command's direct parameter can be any value; the application's dictionary will (usually) indicate the appropriate types. A command can have a maximum of one direct parameter; if more than one is given, an error will occur. Keyword parameters are specified as a <code>Hash</code> object whose keys are symbols representing the parameter names:</p>
35
+
36
+ <pre><code>application.command_name(direct_parameter, {:name1 =&gt; value1, :name2 =&gt; value2, ...})</code></pre>
37
+
38
+ <p>Note that Ruby allows the hash to be written without the enclosing <code>{</code> and <code>}</code> for appearance's sake:</p>
39
+
40
+ <pre><code>application.command_name(direct_parameter, :name1 =&gt; value1, :name2 =&gt; value2, ...)</code></pre>
41
+
42
+ <p>Each command can have zero or more keyword parameters as defined in the application dictionary. In addition, appscript provides the following default parameters for indicating how the command should be handled:</p>
43
+
44
+ <table summary="Default appscript parameters">
45
+ <thead>
46
+ <tr><th>Name</th><th>Class</th><th>Description</th></tr>
47
+ </thead>
48
+ <tbody>
49
+ <tr><td><code>:wait_reply</code></td><td><code>Boolean</code></td><td>Wait for application to return a result/error?</td></tr>
50
+
51
+ <tr><td><code>:timeout</code></td><td><code>Integer</code></td><td>Number of seconds to wait for a reply (no timeout = 0)</td></tr>
52
+
53
+ <tr><td><code>:result_type</code></td><td><code>nil</code> | <code>Symbol</code></td><td>AE type to coerce return value to (e.g. <code>:FSRef</code>)</td></tr>
54
+
55
+ <tr><td><code>:ignore</code></td><td><code>nil</code> | <code>Array of Symbol</code></td><td>String characteristics to ignore when evaluating references. The array should contain zero or more of the following enumerators: <code>:case</code>, <code>:diacriticals</code>, <code>:expansion</code>, <code>:hyphens</code>, <code>:punctuation</code>, <code>:whitespace</code></td></tr>
56
+
57
+ </tbody>
58
+ </table>
59
+
60
+ <p>(Note that most applications currently ignore the <code>:ignore</code> parameter and use the default behaviour, i.e. ignore case.)</p>
61
+
62
+
63
+ <p>For convenience, appscript allows the direct parameter and/or keyword parameters arguments to be omitted from the method's argument list if unused. For example, a command that has no direct or keyword parameters would be written as:</p>
64
+
65
+ <pre><code>application.command_name</code></pre>
66
+
67
+ <p>If the command takes only keyword parameters, or the direct parameter is the reference upon which the command is called, it can be written as:</p>
68
+
69
+ <pre><code>application.command_name(:name1 =&gt; value1, :name2 =&gt; value2, ...)</code></pre>
70
+
71
+ <p>If the command takes only a direct parameter <em>and</em> the value given is not a hash, then it can be written as follows:
72
+
73
+ <pre><code>application.command_name(direct_parameter)</code></pre>
74
+
75
+ <p>If the direct parameter is a Ruby hash, you <em>must</em> provide an empty keyword parameters hash as the second argument to the call:</p>
76
+
77
+ <pre><code>application.command_name(direct_hash_parameter, {})</code></pre>
78
+
79
+ <p>If you forget, appscript will treat this hash value as the command's keyword parameters, resulting in an error or other unexpected behaviour.</p>
80
+
81
+ <p>See the Special cases section below for additional rules.</p>
82
+
83
+ <h2>Examples</h2>
84
+
85
+ <pre><code># tell application &quot;TextEdit&quot; to activate
86
+ AS.app('TextEdit').activate
87
+
88
+ # tell application &quot;TextEdit&quot; to open fileRefList
89
+ AS.app('TextEdit').open(fileRefList)
90
+
91
+ # tell application &quot;Finder&quot; to get version
92
+ AS.app('Finder').version.get
93
+
94
+ # tell application &quot;Finder&quot; to set name of file &quot;foo.txt&quot; of home to &quot;bar.txt&quot;
95
+ AS.app('Finder').home.files['foo.txt'].name.set('bar.txt')
96
+
97
+ # tell application &quot;TextEdit&quot; to count (text of first document) each paragraph
98
+ AS.app('TextEdit').documents.first.text.count(:each =&gt; :paragraph)
99
+
100
+ # tell application &quot;TextEdit&quot; to make new document at end of documents
101
+ AS.app('TextEdit').documents.end.make(:new =&gt; :document)
102
+
103
+ # tell application &quot;Finder&quot; to get items of home as alias list
104
+ AS.app('Finder').home.items.get(:result_type =&gt; :alias)</code></pre>
105
+
106
+
107
+
108
+ <h2>Special cases</h2>
109
+
110
+ <p>The following special-case behaviours are implemented for convenience:</p>
111
+
112
+ <ol>
113
+ <li><p>Commands that take a reference to one or more application objects as a direct parameter may be written in the following form:</p>
114
+
115
+ <pre><code>reference.command(keyword_parameters)</code></pre>
116
+
117
+ <p>The conventional form is also supported should you ever wish (or need) to use it:</p>
118
+
119
+ <pre><code>application.command(keyword_parameters)</code></pre>
120
+
121
+ <p>The two forms are equivalent (appscript converts the first form to the second behind the scenes) although the first form is preferred for conciseness.</p></li>
122
+
123
+
124
+ <li><p>If a command that already has a direct parameter is called on a reference, i.e.:</p>
125
+
126
+ <pre><code>reference.command(direct_parameter[, keyword_parameters])</code></pre>
127
+
128
+ <p>the reference upon which it is called will be packed as a 'subject' attribute. For example, if the <code>make</code> command is called on a reference, the application will use that reference as its insertion location if there is no <code>at</code> keyword parameter given; i.e.:</p>
129
+
130
+ <pre><code>insertion_location.make(:new =&gt; some_class)</code></pre>
131
+
132
+ <p>instead of:</p>
133
+
134
+ <pre><code>application.make(:new =&gt; some_class, :at =&gt; insertion_location)</code></pre></li>
135
+
136
+
137
+ <li><p>When the <code>set</code> command is called on a reference, its <code>to</code> parameter can be written as a direct parameter; i.e.:</p>
138
+
139
+ <pre><code>reference.set(value)</code></pre>
140
+
141
+ <p>instead of:</p>
142
+
143
+ <pre><code>reference.set(:to =&gt; value)</code></pre>
144
+
145
+ <p>or:</p>
146
+
147
+ <pre><code>application.set(reference, :to =&gt; value)</code></pre>
148
+
149
+ <p>The first form is preferred, although all three are supported.</p></li>
150
+
151
+ </ol>
152
+
153
+
154
+ <h2>Note to AppleScript users</h2>
155
+
156
+ <p>Unlike AppleScript, which implicitly sends a <code>get</code> command to any unresolved application object references at the end of evaluating an expression, appscript only resolves a reference when it receives an appropriate command. For example:</p>
157
+
158
+ <pre><code>foo = AS.app('Finder').disks</code></pre>
159
+
160
+ <p>is <em>not</em> equivalent to:</p>
161
+
162
+ <pre><code>set foo to disks of application &quot;Finder&quot;</code></pre>
163
+
164
+ <p>even though the two may look similar. In the first case, the value assigned to variable <code>foo</code> is a reference, <code>AS.app('Finder').disks</code>. In the second, AppleScript evaluates the <code>disks of application &quot;Finder&quot;</code> reference by performing an implicit <code>get</code> command before assigning the result, a <em>list</em> containing one or more references (one to each disk currently mounted), to variable <code>foo</code>. To assign an unresolved reference to a variable in AppleScript, the reference must be preceded by the <code>a reference to</code> operator. For example:</p>
165
+
166
+ <ul>
167
+ <li><p>Getting a reference to all disks:</p>
168
+
169
+ <pre><code>set foo to a reference to every disk of application &quot;Finder&quot;
170
+ return foo
171
+ --&gt; a reference to every disk of application &quot;Finder&quot;</code></pre>
172
+
173
+ <pre><code>foo = AS.app('Finder').disks
174
+ print foo
175
+ --&gt; AS.app('Finder').disks</code></pre></li>
176
+
177
+
178
+ <li><p>Getting a list of references to each disk:</p>
179
+
180
+ <pre><code>set foo to get every disk of application &quot;Finder&quot; -- (the 'get' is optional here)
181
+ return foo
182
+ --&gt; {disk &quot;Mac HD&quot; of application &quot;Finder&quot;, disk &quot;ZIP-100&quot; of application &quot;Finder&quot;}</code></pre>
183
+
184
+ <pre><code>foo = AS.app('Finder').disks.get
185
+ print foo
186
+ --&gt; [AS.app('Finder').disks['Mac HD'], AS.app('Finder').disks['ZIP-100']]</code></pre>
187
+
188
+ </li>
189
+ </ul>
190
+
191
+
192
+
193
+ </div>
194
+
195
+ <!-- bottom navigation -->
196
+ <div class="navbar">
197
+ <a href="10_referenceexamples.html">Previous</a> | <a href="index.html">Up</a> | <a href="12_commandexamples.html">Next</a>
198
+
199
+ </div>
200
+
201
+ <!--footer-->
202
+ <p class="footer">&copy; 2006 HAS</p>
203
+ </body>
204
+ </html>