rb-scpt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +497 -0
  3. data/doc/aem-manual/01_introduction.html +60 -0
  4. data/doc/aem-manual/02_apioverview.html +107 -0
  5. data/doc/aem-manual/03_packingandunpackingdata.html +135 -0
  6. data/doc/aem-manual/04_references.html +409 -0
  7. data/doc/aem-manual/05_targetingapplications.html +164 -0
  8. data/doc/aem-manual/06_buildingandsendingevents.html +229 -0
  9. data/doc/aem-manual/07_findapp.html +63 -0
  10. data/doc/aem-manual/08_examples.html +94 -0
  11. data/doc/aem-manual/aemreferenceinheritance.gif +0 -0
  12. data/doc/aem-manual/index.html +56 -0
  13. data/doc/appscript-manual/01_introduction.html +94 -0
  14. data/doc/appscript-manual/02_aboutappscripting.html +247 -0
  15. data/doc/appscript-manual/03_quicktutorial.html +167 -0
  16. data/doc/appscript-manual/04_gettinghelp.html +188 -0
  17. data/doc/appscript-manual/05_keywordconversion.html +106 -0
  18. data/doc/appscript-manual/06_classesandenums.html +192 -0
  19. data/doc/appscript-manual/07_applicationobjects.html +211 -0
  20. data/doc/appscript-manual/08_realvsgenericreferences.html +96 -0
  21. data/doc/appscript-manual/09_referenceforms.html +241 -0
  22. data/doc/appscript-manual/10_referenceexamples.html +154 -0
  23. data/doc/appscript-manual/11_applicationcommands.html +245 -0
  24. data/doc/appscript-manual/12_commandexamples.html +138 -0
  25. data/doc/appscript-manual/13_performanceissues.html +142 -0
  26. data/doc/appscript-manual/14_notes.html +80 -0
  27. data/doc/appscript-manual/application_architecture.gif +0 -0
  28. data/doc/appscript-manual/application_architecture2.gif +0 -0
  29. data/doc/appscript-manual/finder_to_textedit_event.gif +0 -0
  30. data/doc/appscript-manual/index.html +62 -0
  31. data/doc/appscript-manual/relationships_example.gif +0 -0
  32. data/doc/appscript-manual/ruby_to_itunes_event.gif +0 -0
  33. data/doc/full.css +106 -0
  34. data/doc/index.html +45 -0
  35. data/doc/mactypes-manual/01_introduction.html +54 -0
  36. data/doc/mactypes-manual/02_aliasclass.html +124 -0
  37. data/doc/mactypes-manual/03_fileurlclass.html +126 -0
  38. data/doc/mactypes-manual/04_unitsclass.html +100 -0
  39. data/doc/mactypes-manual/index.html +53 -0
  40. data/doc/osax-manual/01_introduction.html +67 -0
  41. data/doc/osax-manual/02_interface.html +147 -0
  42. data/doc/osax-manual/03_examples.html +73 -0
  43. data/doc/osax-manual/04_notes.html +61 -0
  44. data/doc/osax-manual/index.html +53 -0
  45. data/doc/rb-appscript-logo.png +0 -0
  46. data/extconf.rb +65 -0
  47. data/rb-scpt.gemspec +14 -0
  48. data/sample/AB_export_vcard.rb +31 -0
  49. data/sample/AB_list_people_with_emails.rb +13 -0
  50. data/sample/Add_iCal_event.rb +21 -0
  51. data/sample/Create_daily_iCal_todos.rb +75 -0
  52. data/sample/Export_Address_Book_phone_numbers.rb +59 -0
  53. data/sample/Hello_world.rb +21 -0
  54. data/sample/List_iTunes_playlist_names.rb +11 -0
  55. data/sample/Make_Mail_message.rb +33 -0
  56. data/sample/Open_file_in_TextEdit.rb +13 -0
  57. data/sample/Organize_Mail_messages.rb +61 -0
  58. data/sample/Print_folder_tree.rb +16 -0
  59. data/sample/Select_all_HTML_files.rb +14 -0
  60. data/sample/Set_iChat_status.rb +24 -0
  61. data/sample/Simple_Finder_GUI_Scripting.rb +18 -0
  62. data/sample/Stagger_Finder_windows.rb +25 -0
  63. data/sample/TextEdit_demo.rb +130 -0
  64. data/sample/iTunes_top40_to_html.rb +71 -0
  65. data/src/SendThreadSafe.c +380 -0
  66. data/src/SendThreadSafe.h +139 -0
  67. data/src/lib/_aem/aemreference.rb +1022 -0
  68. data/src/lib/_aem/codecs.rb +662 -0
  69. data/src/lib/_aem/connect.rb +205 -0
  70. data/src/lib/_aem/encodingsupport.rb +77 -0
  71. data/src/lib/_aem/findapp.rb +85 -0
  72. data/src/lib/_aem/mactypes.rb +251 -0
  73. data/src/lib/_aem/send.rb +279 -0
  74. data/src/lib/_aem/typewrappers.rb +59 -0
  75. data/src/lib/_appscript/defaultterminology.rb +277 -0
  76. data/src/lib/_appscript/referencerenderer.rb +245 -0
  77. data/src/lib/_appscript/reservedkeywords.rb +116 -0
  78. data/src/lib/_appscript/safeobject.rb +249 -0
  79. data/src/lib/_appscript/terminology.rb +471 -0
  80. data/src/lib/aem.rb +253 -0
  81. data/src/lib/appscript.rb +1075 -0
  82. data/src/lib/kae.rb +1489 -0
  83. data/src/lib/osax.rb +659 -0
  84. data/src/rbae.c +979 -0
  85. data/test/README +3 -0
  86. data/test/test_aemreference.rb +118 -0
  87. data/test/test_appscriptcommands.rb +152 -0
  88. data/test/test_appscriptreference.rb +106 -0
  89. data/test/test_codecs.rb +186 -0
  90. data/test/test_findapp.rb +26 -0
  91. data/test/test_mactypes.rb +79 -0
  92. data/test/test_osax.rb +54 -0
  93. data/test/testall.sh +10 -0
  94. metadata +145 -0
@@ -0,0 +1,241 @@
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>rb-appscript manual | 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><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
14
+
15
+ <!-- top navigation -->
16
+ <div class="navbar">
17
+ <a href="08_realvsgenericreferences.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="10_referenceexamples.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>
27
+ </div>
28
+
29
+ <!-- content -->
30
+ <div id="content">
31
+
32
+ <h2>9. Reference Forms</h2>
33
+
34
+ <h3>Property reference</h3>
35
+
36
+ <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>
37
+
38
+ <p>Syntax:</p>
39
+ <pre><code>reference.property</code></pre>
40
+
41
+ <p>Examples:</p>
42
+ <pre><code>textedit.<em>name</em>
43
+ textedit.documents[1].<em>text</em>
44
+ finder.<em>home</em>.files.<em>name</em></code></pre>
45
+
46
+
47
+
48
+ <h3>Element references</h3>
49
+
50
+ <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>
51
+
52
+ <h4>All Elements</h4>
53
+
54
+ <p>Syntax:</p>
55
+ <pre><code>reference.elements</code></pre>
56
+
57
+ <p>Examples:</p>
58
+ <pre><code>finder.home.<em>folders</em>
59
+ textedit.<em>windows</em>
60
+ textedit.<em>documents</em>.<em>paragraphs</em>.<em>words</em></code></pre>
61
+
62
+
63
+ <h4>by Name</h4>
64
+
65
+ <p>Syntax:</p>
66
+ <pre><code>elements[selector]
67
+ selector : String -- name of object (as matches its 'name' property)</code></pre>
68
+
69
+ <p>Examples:</p>
70
+ <pre><code>disks['Macintosh HD']
71
+ files['index.html']</code></pre>
72
+
73
+ <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>
74
+
75
+
76
+ <h4>by Index</h4>
77
+
78
+ <p>Syntax:</p>
79
+ <pre><code>elements[selector]
80
+ selector : Fixnum | Bignum -- index of object</code></pre>
81
+
82
+ <p>Examples:</p>
83
+ <pre><code>words[3]
84
+ items[-1]</code></pre>
85
+
86
+ <p class="hilitebox">Note: elements are <em>one-indexed</em> (AEM-style indexing), not zero-indexed (Ruby-style indexing).</p>
87
+
88
+
89
+ <h4>by ID</h4>
90
+
91
+ <p>Syntax:</p>
92
+ <pre><code>elements.ID(selector)
93
+ selector : anything -- object's id</code></pre>
94
+
95
+ <p>Examples:</p>
96
+ <pre><code>windows.ID(4321)</code></pre>
97
+
98
+
99
+ <h4>by Absolute Position</h4>
100
+
101
+ <p>Syntax:</p>
102
+ <pre><code>elements.first -- first element
103
+ elements.middle -- middle element
104
+ elements.last -- last element
105
+ elements.any -- random element</code></pre>
106
+
107
+ <p>Examples:</p>
108
+ <pre><code>documents.first
109
+ paragraphs.last
110
+ files.any</code></pre>
111
+
112
+
113
+ <h4>by Relative Position</h4>
114
+
115
+ <p>Syntax:</p>
116
+ <pre><code>elements[selector].previous(class) -- nearest element of a given class to appear
117
+ before the specified element
118
+ elements[selector].next(class) -- nearest element of a given class to appear
119
+ after the specified element
120
+ class : Symbol -- class of element (see <a href="06_classesandenums.html">Classes and Enumerated Types</a>)</code></pre>
121
+
122
+ <p>Examples:</p>
123
+ <pre><code>words[3].next(:word)
124
+ paragraphs[-1].previous(:character)</code></pre>
125
+
126
+
127
+ <h4>by Range</h4>
128
+
129
+ <p>Range references select all elements between and including two references indicating the start and stop of the range. The start and stop 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>
130
+
131
+ <pre><code>con.paragraphs[3]</code></pre>
132
+
133
+ <p>For convenience, the range reference also allows start and stop references to be written in shorthand form where their element class is the same as the elements being selected; thus:</p>
134
+
135
+ <pre><code>ref.paragraphs[con.paragraphs[3], con.paragraphs[-1]]</code></pre>
136
+
137
+ <p>can also be written as:</p>
138
+
139
+ <pre><code>ref.paragraphs[3:-1]</code></pre>
140
+
141
+ <p>Some applications can handle more complex range references. For example, the following will work in Tex-Edit Plus:</p>
142
+
143
+ <pre><code>ref.words[con.characters[5], con.paragraphs[-2]]</code></pre>
144
+
145
+ <p>Syntax:</p>
146
+ <pre><code>elements[start, stop]
147
+ start : Fixnum | Bignum | String | Reference -- beginning of range
148
+ stop : Fixnum | Bignum | String | Reference -- end of range</code></pre>
149
+
150
+ <p>Examples:</p>
151
+ <pre><code>folders['Documents', 'Movies']
152
+ documents[1, 3]
153
+ text[con.characters[5], con.words[-2]]</code></pre>
154
+
155
+ <p class="hilitebox">Note: ranges are specified as [start-position, <em>stop-position</em>] (AEM-style ranges), not [start-position, <em>length</em>] (Ruby-style ranges).</p>
156
+
157
+ <h4>by Filter</h4>
158
+
159
+ <p>A reference to each element that satisfies one or more conditions specified by a test expression:</p>
160
+
161
+ <pre><code>elements[testExpression]</code></pre>
162
+
163
+ <p>Test expressions consist of the following:</p>
164
+
165
+ <ul>
166
+ <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>
167
+
168
+ <pre><code>its
169
+ its.size
170
+ its.words.first</code></pre></li>
171
+
172
+ <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 its sole argument.</p>
173
+
174
+ <p>Syntax:</p>
175
+ <pre><code>reference.lt(value) # &lt;
176
+ reference.le(value) # &lt;=
177
+ reference.eq(value) # ==
178
+ reference.ne(value) # !=
179
+ reference.gt(value) # &gt;
180
+ reference.ge(value) # &gt;=
181
+ reference.begins_with(value)
182
+ reference.ends_with(value)
183
+ reference.contains(value)
184
+ reference.is_in(value)
185
+ reference.does_not_begin_with(value)
186
+ reference.does_not_end_with(value)
187
+ reference.does_not_contain(value)
188
+ reference.is_not_in(value)
189
+ value : reference or value</code></pre>
190
+
191
+ <p>Examples:</p>
192
+ <pre><code>its.eq('')
193
+ its.size.gt(1024)
194
+ its.words.first.begins_with('A')
195
+ its.characters.first.eq(its.characters.last)</code></pre>
196
+
197
+ <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>
198
+
199
+ <p>Syntax:</p>
200
+ <pre><code>test.and(test, ...)
201
+ test.or(test, ...)
202
+ test.not</code></pre>
203
+
204
+ <p>Examples:</p>
205
+ <pre><code>its.eq('').not
206
+ its.size.gt(1024).and(its.size.lt(10240))
207
+ its.words[1].begins_with('A').or(
208
+ its.words[2].contains('ce'),
209
+ its.words[1].eq('Foo'))</code></pre></li>
210
+ </ul>
211
+
212
+
213
+
214
+ <h3>Insertion location</h3>
215
+
216
+ <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>
217
+
218
+ <p>Syntax:</p>
219
+ <pre><code>elements.beginning
220
+ elements.end
221
+ elements[selector].before
222
+ elements[selector].after</code></pre>
223
+
224
+ <p>Examples:</p>
225
+ <pre><code>documents.end
226
+ paragraphs[1].before</code></pre>
227
+
228
+
229
+
230
+ </div>
231
+
232
+ <!-- bottom navigation -->
233
+
234
+ <div class="footer">
235
+ <a href="08_realvsgenericreferences.html">Previous</a> &bull;
236
+ <a href="index.html">Up</a> &bull;
237
+ <a href="10_referenceexamples.html">Next</a>
238
+ </div>
239
+
240
+ </body>
241
+ </html>
@@ -0,0 +1,154 @@
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>rb-appscript manual | 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><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
14
+
15
+ <!-- top navigation -->
16
+ <div class="navbar">
17
+ <a href="09_referenceforms.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="11_applicationcommands.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>
27
+ </div>
28
+
29
+ <!-- content -->
30
+ <div id="content">
31
+
32
+ <h2>10. Reference Examples</h2>
33
+
34
+ <h3>Application objects</h3>
35
+
36
+ <pre><code>require "appscript"
37
+ include Appscript
38
+
39
+ # application &quot;Finder&quot;
40
+ app('Finder')
41
+
42
+ # application &quot;Macintosh HD:Applications:TextEdit.app:&quot;
43
+ app('/Applications/TextEdit.app')</code></pre>
44
+
45
+
46
+ <h3>Property references</h3>
47
+
48
+ <pre><code># a reference to startup disk of application &quot;Finder&quot;
49
+ app('Finder').startup_disk
50
+
51
+ # a reference to name of folder 1 of home of application &quot;Finder&quot;
52
+ app('Finder').home.folders[1].name
53
+
54
+ # a reference to name of every item of home of application &quot;Finder&quot;
55
+ app('Finder').home.items.name
56
+
57
+ # a reference to text of every document of application &quot;TextEdit&quot;
58
+ app('TextEdit').documents.text
59
+
60
+ # a reference to color of character 1 of every paragraph of text &not;
61
+ # of document 1 of application &quot;TextEdit&quot;
62
+ app('TextEdit').documents[1].text.paragraphs.characters[1].color</code></pre>
63
+
64
+
65
+ <h3>All elements references</h3>
66
+
67
+ <pre><code># a reference to disks of application &quot;Finder&quot;
68
+ app('Finder').disks
69
+
70
+ # a reference to every word of every paragraph of text of every document &not;
71
+ # of application &quot;TextEdit&quot;
72
+ app('TextEdit').documents.text.paragraphs.words</code></pre>
73
+
74
+
75
+ <h3>Single element references</h3>
76
+
77
+ <pre><code># a reference to disk 1 of application &quot;Finder&quot;
78
+ app('Finder').disks[1]
79
+
80
+ # a reference to file &quot;ReadMe.txt&quot; of folder &quot;Documents&quot; of home of application &quot;Finder&quot;
81
+ app('Finder').home.folders['Documents'].files['ReadMe.txt']
82
+
83
+ # a reference to paragraph -1 of text of document 1 of application &quot;TextEdit&quot;
84
+ app('TextEdit').documents[1].text.paragraphs[-1]
85
+
86
+ # a reference to middle paragraph of text of last document of application &quot;TextEdit&quot;
87
+ app('TextEdit').documents.last.text.paragraphs.middle
88
+
89
+ # a reference to any file of home of application &quot;Finder&quot;
90
+ app('Finder').home.files.any</code></pre>
91
+
92
+
93
+ <h3>Relative references</h3>
94
+
95
+ <pre><code># a reference to paragraph before paragraph 6 of text of document 1 of application &quot;TextEdit&quot;
96
+ app('TextEdit').documents[1].text.paragraphs[6].previous(:paragraph)
97
+
98
+ # a reference to paragraph after character 30 of document 1 of application &quot;Tex-Edit Plus&quot;
99
+ app('Tex-Edit Plus').documents[1].characters[30].next(:paragraph)</code></pre>
100
+
101
+
102
+ <h3>Element range references</h3>
103
+
104
+ <pre><code># a reference to words 1 thru 4 of text of document 1 of application &quot;TextEdit&quot;
105
+ app('TextEdit').documents[1].text.words[1, 4]
106
+
107
+ # a reference to paragraphs 2 thru -1 of text of document 1 of application &quot;TextEdit&quot;
108
+ app('TextEdit').documents[1].text.paragraphs[2, -1]
109
+
110
+ # a reference to folders &quot;Documents&quot; thru &quot;Music&quot; of home of application &quot;Finder&quot;
111
+ app('Finder').home.folders['Documents', 'Music']
112
+
113
+ # a reference to text (word 3) thru (paragraph 7) of document 1 of application &quot;Tex-Edit Plus&quot;
114
+ app('Tex-Edit Plus').documents[1].text[con.words[3], con.paragraphs[7]]</code></pre>
115
+
116
+
117
+ <h3>Filter references</h3>
118
+
119
+ <pre><code># a reference to every document of application &quot;TextEdit&quot; whose text is &quot;\n&quot;
120
+ app('TextEdit').documents[its.text.eq("\n")]
121
+
122
+ # a reference to every paragraph of document 1 of application &quot;Tex-Edit Plus&quot; &not;
123
+ # whose first character is last character
124
+ app('Tex-Edit Plus').documents[1].paragraphs[
125
+ its.characters.first.eq(its.characters.last)]
126
+
127
+ # a reference to every file of folder &quot;Documents&quot; of home of application &quot;Finder&quot; &not;
128
+ # whose name extension is &quot;txt&quot; and size < 10240
129
+ app('Finder').home.folders['Documents'].files[
130
+ its.name_extension.eq('txt').and(its.size.lt(10240))]</code></pre>
131
+
132
+
133
+ <h3>Insertion location references</h3>
134
+
135
+ <pre><code># a reference to end of documents of application &quot;TextEdit&quot;
136
+ app('TextEdit').documents.end
137
+
138
+ # a reference to before paragraph 1 of text of document 1 of application &quot;TextEdit&quot;
139
+ app('TextEdit').documents[1].text.paragraphs[1].before</code></pre>
140
+
141
+
142
+
143
+ </div>
144
+
145
+ <!-- bottom navigation -->
146
+
147
+ <div class="footer">
148
+ <a href="09_referenceforms.html">Previous</a> &bull;
149
+ <a href="index.html">Up</a> &bull;
150
+ <a href="11_applicationcommands.html">Next</a>
151
+ </div>
152
+
153
+ </body>
154
+ </html>
@@ -0,0 +1,245 @@
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>rb-appscript manual | 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><img src="../rb-appscript-logo.png" alt="rb-appscript" title="rb-appscript" /></h1>
14
+
15
+ <!-- top navigation -->
16
+ <div class="navbar">
17
+ <a href="10_referenceexamples.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="12_commandexamples.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>
27
+ </div>
28
+
29
+ <!-- content -->
30
+ <div id="content">
31
+
32
+ <h2>11. Application Commands</h2>
33
+
34
+ <h3>Command syntax</h3>
35
+
36
+ <p>Appscript commands have the following syntax:</p>
37
+
38
+ <pre><code>application.command_name([direct_parameter][, keyword_parameters])</code></pre>
39
+
40
+ <p>Both direct and keyword parameters are optional.</p>
41
+
42
+ <p>Application commands are implemented by the application's top-level <code>application</code> object (represented by an <code>Appscript::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>
43
+
44
+ <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>
45
+
46
+ <pre><code>application.command_name(direct_parameter, {:name1 =&gt; value1, :name2 =&gt; value2, ...})</code></pre>
47
+
48
+ <p>Note that Ruby allows the hash to be written without the enclosing <code>{</code> and <code>}</code> for appearance's sake:</p>
49
+
50
+ <pre><code>application.command_name(direct_parameter, :name1 =&gt; value1, :name2 =&gt; value2, ...)</code></pre>
51
+
52
+ <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>
53
+
54
+ <table summary="Default appscript parameters">
55
+ <thead>
56
+ <tr><th>Name</th><th>Class</th><th>Description</th></tr>
57
+ </thead>
58
+ <tbody>
59
+ <tr><td><code>:wait_reply</code></td><td><code>Boolean</code></td><td>Wait for application to return a result/error?</td></tr>
60
+
61
+ <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>
62
+
63
+ <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>
64
+
65
+ <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>
66
+
67
+ </tbody>
68
+ </table>
69
+
70
+ <p>(Note that most applications currently ignore the <code>:ignore</code> parameter and use the default behaviour, i.e. ignore case.)</p>
71
+
72
+
73
+ <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>
74
+
75
+ <pre><code>application.command_name</code></pre>
76
+
77
+ <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>
78
+
79
+ <pre><code>application.command_name(:name1 =&gt; value1, :name2 =&gt; value2, ...)</code></pre>
80
+
81
+ <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:
82
+
83
+ <pre><code>application.command_name(direct_parameter)</code></pre>
84
+
85
+ <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>
86
+
87
+ <pre><code>application.command_name(direct_hash_parameter, {})</code></pre>
88
+
89
+ <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>
90
+
91
+ <p>See the Special cases section below for additional rules.</p>
92
+
93
+ <h3>Examples</h3>
94
+
95
+ <pre><code># tell application &quot;TextEdit&quot; to activate
96
+ app('TextEdit').activate
97
+
98
+ # tell application &quot;TextEdit&quot; to open fileRefList
99
+ app('TextEdit').open(fileRefList)
100
+
101
+ # tell application &quot;Finder&quot; to get version
102
+ app('Finder').version.get
103
+
104
+ # tell application &quot;Finder&quot; to set name of file &quot;foo.txt&quot; of home to &quot;bar.txt&quot;
105
+ app('Finder').home.files['foo.txt'].name.set('bar.txt')
106
+
107
+ # tell application &quot;TextEdit&quot; to count (text of first document) each paragraph
108
+ app('TextEdit').documents.first.text.count(:each =&gt; :paragraph)
109
+
110
+ # tell application &quot;TextEdit&quot; to make new document at end of documents
111
+ app('TextEdit').documents.end.make(:new =&gt; :document)
112
+
113
+ # tell application &quot;Finder&quot; to get items of home as alias list
114
+ app('Finder').home.items.get(:result_type =&gt; :alias)</code></pre>
115
+
116
+
117
+
118
+ <h3>Special cases</h3>
119
+
120
+ <p>The following special-case behaviours are implemented for convenience:</p>
121
+
122
+ <ol>
123
+ <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>
124
+
125
+ <pre><code>reference.command(keyword_parameters)</code></pre>
126
+
127
+ <p>The conventional form is also supported should you ever wish (or need) to use it:</p>
128
+
129
+ <pre><code>application.command(reference, keyword_parameters)</code></pre>
130
+
131
+ <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>
132
+
133
+
134
+ <li><p>If a command that already has a direct parameter is called on a reference, i.e.:</p>
135
+
136
+ <pre><code>reference.command(direct_parameter[, keyword_parameters])</code></pre>
137
+
138
+ <p>the reference upon which it is called will be packed as the Apple event's 'subject' attribute (<code>keySubjectAttr</code>).</p></li>
139
+
140
+
141
+ <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>
142
+
143
+ <pre><code>reference.set(value)</code></pre>
144
+
145
+ <p>instead of:</p>
146
+
147
+ <pre><code>reference.set(:to =&gt; value)</code></pre>
148
+
149
+ <p>or:</p>
150
+
151
+ <pre><code>application.set(reference, :to =&gt; value)</code></pre>
152
+
153
+ <p>The first form is preferred, although all three are supported.</p></li>
154
+
155
+
156
+ <li><p>If the <code>make</code> command is called on an insertion location reference, appscript will pack that reference as the Apple event's <code>at</code> parameter if it doesn't already have one; i.e.:</p>
157
+
158
+ <pre><code>insertion_location.make(:new =&gt; some_class)</code></pre>
159
+
160
+ <p>is equivalent to:</p>
161
+
162
+ <pre><code>application.make(:new =&gt; some_class, :at =&gt; insertion_location)</code></pre>
163
+
164
+ <p>If the <code>make</code> command is called on an object reference, appscript will pack that reference as the Apple event's 'subject' attribute. (Note that some applications may not handle the subject attribute correctly, in which case the reference should be passed as the <code>make</code> command's <code>at</code> parameter instead.)</p></li>
165
+
166
+ </ol>
167
+
168
+
169
+ <h3>Command errors</h3>
170
+
171
+
172
+ <p>The <code>Appscript::CommandError</code> exception describes an error raised by the target application or Apple Event Manager when sending a command.</p>
173
+
174
+ <pre><code>CommandError < RuntimeError
175
+
176
+ Methods:
177
+
178
+ error_number : FixNum -- Mac OS error number
179
+
180
+ error_message : String -- application-supplied/generic error description
181
+
182
+ offending_object : anything | nil -- object that caused the error,
183
+ if given by application
184
+
185
+ expected_type : anything | nil -- object that caused a coercion error,
186
+ if given by application
187
+
188
+ partial_result : anything | nil -- part of return value constructed
189
+ before error occurred, if given
190
+ by application
191
+
192
+ to_i : FixNum -- equivalent to #error_number
193
+
194
+ to_s : String -- formatted error information</code></pre>
195
+
196
+
197
+
198
+ <h3>Note to AppleScript users</h3>
199
+
200
+ <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>
201
+
202
+ <pre><code>d = app('TextEdit').documents</code></pre>
203
+
204
+ <p>is <em>not</em> the same as:</p>
205
+
206
+ <pre><code>set d to documents of app &quot;TextEdit&quot;</code></pre>
207
+
208
+ <p>even though the two may look similar. In the first case, the value assigned to <code>d</code> is an appscript reference: <code>app('TextEdit').documents</code>. In the second, AppleScript evaluates the <code>documents of app &quot;TextEdit&quot;</code> reference by performing an implicit <code>get</code> command and then assigning its result, a list of references to individual documents, to <code>d</code>. To obtain the original reference as an AppleScript value, the literal reference must be preceded by an <code>a reference to</code> operator as shown below.</p>
209
+
210
+ <p>To get a single reference to all documents:</p>
211
+
212
+ <pre><code>set d to a reference to documents of app &quot;TextEdit&quot;
213
+ return d
214
+ --&gt; a reference to documents of app &quot;TextEdit&quot;
215
+
216
+
217
+ d = app('TextEdit').documents
218
+ print d
219
+ --&gt; app('TextEdit').documents</code></pre>
220
+
221
+
222
+ <p>To get a list of references to each document:</p>
223
+
224
+ <pre><code>set d to get documents of app &quot;TextEdit&quot; -- (explicit 'get' is optional)
225
+ return d
226
+ --&gt; {document 1 of app &quot;TextEdit&quot;, document 2 of app &quot;TextEdit&quot;}
227
+
228
+
229
+ d = app('TextEdit').documents.get -- (explicit 'get' is required)
230
+ print d
231
+ --&gt; [app('TextEdit').documents[1], app('TextEdit').documents[2]]</code></pre>
232
+
233
+
234
+ </div>
235
+
236
+ <!-- bottom navigation -->
237
+
238
+ <div class="footer">
239
+ <a href="10_referenceexamples.html">Previous</a> &bull;
240
+ <a href="index.html">Up</a> &bull;
241
+ <a href="12_commandexamples.html">Next</a>
242
+ </div>
243
+
244
+ </body>
245
+ </html>