rb-scrpt 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +497 -0
  3. data/README.md +8 -0
  4. data/Rakefile +32 -0
  5. data/doc/aem-manual/01_introduction.html +60 -0
  6. data/doc/aem-manual/02_apioverview.html +107 -0
  7. data/doc/aem-manual/03_packingandunpackingdata.html +135 -0
  8. data/doc/aem-manual/04_references.html +409 -0
  9. data/doc/aem-manual/05_targetingapplications.html +164 -0
  10. data/doc/aem-manual/06_buildingandsendingevents.html +229 -0
  11. data/doc/aem-manual/07_findapp.html +63 -0
  12. data/doc/aem-manual/08_examples.html +94 -0
  13. data/doc/aem-manual/aemreferenceinheritance.gif +0 -0
  14. data/doc/aem-manual/index.html +56 -0
  15. data/doc/appscript-manual/01_introduction.html +94 -0
  16. data/doc/appscript-manual/02_aboutappscripting.html +247 -0
  17. data/doc/appscript-manual/03_quicktutorial.html +167 -0
  18. data/doc/appscript-manual/04_gettinghelp.html +188 -0
  19. data/doc/appscript-manual/05_keywordconversion.html +106 -0
  20. data/doc/appscript-manual/06_classesandenums.html +192 -0
  21. data/doc/appscript-manual/07_applicationobjects.html +211 -0
  22. data/doc/appscript-manual/08_realvsgenericreferences.html +96 -0
  23. data/doc/appscript-manual/09_referenceforms.html +241 -0
  24. data/doc/appscript-manual/10_referenceexamples.html +154 -0
  25. data/doc/appscript-manual/11_applicationcommands.html +245 -0
  26. data/doc/appscript-manual/12_commandexamples.html +138 -0
  27. data/doc/appscript-manual/13_performanceissues.html +142 -0
  28. data/doc/appscript-manual/14_notes.html +80 -0
  29. data/doc/appscript-manual/application_architecture.gif +0 -0
  30. data/doc/appscript-manual/application_architecture2.gif +0 -0
  31. data/doc/appscript-manual/finder_to_textedit_event.gif +0 -0
  32. data/doc/appscript-manual/index.html +62 -0
  33. data/doc/appscript-manual/relationships_example.gif +0 -0
  34. data/doc/appscript-manual/ruby_to_itunes_event.gif +0 -0
  35. data/doc/full.css +106 -0
  36. data/doc/index.html +45 -0
  37. data/doc/mactypes-manual/01_introduction.html +54 -0
  38. data/doc/mactypes-manual/02_aliasclass.html +124 -0
  39. data/doc/mactypes-manual/03_fileurlclass.html +126 -0
  40. data/doc/mactypes-manual/04_unitsclass.html +100 -0
  41. data/doc/mactypes-manual/index.html +53 -0
  42. data/doc/osax-manual/01_introduction.html +67 -0
  43. data/doc/osax-manual/02_interface.html +147 -0
  44. data/doc/osax-manual/03_examples.html +73 -0
  45. data/doc/osax-manual/04_notes.html +61 -0
  46. data/doc/osax-manual/index.html +53 -0
  47. data/doc/rb-appscript-logo.png +0 -0
  48. data/extconf.rb +63 -0
  49. data/rb-scrpt.gemspec +16 -0
  50. data/sample/AB_export_vcard.rb +31 -0
  51. data/sample/AB_list_people_with_emails.rb +13 -0
  52. data/sample/Add_iCal_event.rb +21 -0
  53. data/sample/Create_daily_iCal_todos.rb +75 -0
  54. data/sample/Export_Address_Book_phone_numbers.rb +59 -0
  55. data/sample/Hello_world.rb +21 -0
  56. data/sample/List_iTunes_playlist_names.rb +11 -0
  57. data/sample/Make_Mail_message.rb +33 -0
  58. data/sample/Open_file_in_TextEdit.rb +13 -0
  59. data/sample/Organize_Mail_messages.rb +61 -0
  60. data/sample/Print_folder_tree.rb +16 -0
  61. data/sample/Select_all_HTML_files.rb +14 -0
  62. data/sample/Set_iChat_status.rb +24 -0
  63. data/sample/Simple_Finder_GUI_Scripting.rb +18 -0
  64. data/sample/Stagger_Finder_windows.rb +25 -0
  65. data/sample/TextEdit_demo.rb +130 -0
  66. data/sample/iTunes_top40_to_html.rb +69 -0
  67. data/src/SendThreadSafe.c +380 -0
  68. data/src/SendThreadSafe.h +139 -0
  69. data/src/lib/_aem/aemreference.rb +1021 -0
  70. data/src/lib/_aem/codecs.rb +661 -0
  71. data/src/lib/_aem/connect.rb +205 -0
  72. data/src/lib/_aem/encodingsupport.rb +74 -0
  73. data/src/lib/_aem/findapp.rb +85 -0
  74. data/src/lib/_aem/mactypes.rb +250 -0
  75. data/src/lib/_aem/send.rb +279 -0
  76. data/src/lib/_aem/typewrappers.rb +59 -0
  77. data/src/lib/_appscript/defaultterminology.rb +277 -0
  78. data/src/lib/_appscript/referencerenderer.rb +242 -0
  79. data/src/lib/_appscript/reservedkeywords.rb +116 -0
  80. data/src/lib/_appscript/safeobject.rb +250 -0
  81. data/src/lib/_appscript/terminology.rb +470 -0
  82. data/src/lib/aem.rb +253 -0
  83. data/src/lib/kae.rb +1489 -0
  84. data/src/lib/osax.rb +659 -0
  85. data/src/lib/rb-scrpt.rb +1073 -0
  86. data/src/lib/version.rb +3 -0
  87. data/src/rbae.c +979 -0
  88. data/test/README +3 -0
  89. data/test/test_aemreference.rb +115 -0
  90. data/test/test_appscriptcommands.rb +149 -0
  91. data/test/test_appscriptreference.rb +103 -0
  92. data/test/test_codecs.rb +181 -0
  93. data/test/test_findapp.rb +23 -0
  94. data/test/test_mactypes.rb +77 -0
  95. data/test/test_osax.rb +52 -0
  96. metadata +146 -0
@@ -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>
@@ -0,0 +1,138 @@
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 | 12. Command 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="11_applicationcommands.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="13_performanceissues.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>12. Command Examples</h2>
33
+
34
+ <h3><code>get</code></h3>
35
+
36
+ <p>Get the name of every folder in the user's home folder:</p>
37
+
38
+ <pre><code># tell application "Finder" to get name of every folder of home
39
+
40
+ app('Finder').get(app.home.folders.name)</code></pre>
41
+
42
+ <p>Note that if the direct parameter is omitted from the argument list, the reference that the command is invoked on is used instead. For example, the above example would normally be written as:</p>
43
+
44
+ <pre><code>app('Finder').home.folders.name.get</code></pre>
45
+
46
+
47
+ <h3><code>set</code></h3>
48
+
49
+ <p>Set the content of a TextEdit document:</p>
50
+
51
+ <pre><code># tell application "TextEdit" to set text of document 1 to "Hello World"
52
+
53
+ app('TextEdit').documents[1].text.set('Hello World')</code></pre>
54
+
55
+
56
+ <h3><code>count</code></h3>
57
+
58
+ <p>Count the words in a TextEdit document:</p>
59
+
60
+ <pre><code># tell application "TextEdit" to count words of document 1
61
+
62
+ app('TextEdit').documents[1].words.count</code></pre>
63
+
64
+ <p>Count the items in the current user's home folder:</p>
65
+
66
+ <pre><code>#tell application "Finder" to count items of home
67
+
68
+ app('Finder').home.count(:each =&gt; :item)</code></pre>
69
+
70
+ <p>(Note that the <code>each</code> parameter is required in Finder's <code>count</code> command.)</p>
71
+
72
+
73
+ <h3><code>make</code></h3>
74
+
75
+ <p>Create a new TextEdit document:</p>
76
+
77
+ <pre><code># tell application "TextEdit" to make new document &not;
78
+ # with properties {text:"Hello World\n"}
79
+
80
+ app('TextEdit').make(
81
+ :new =&gt; :document,
82
+ :with_properties =&gt; {:text =&gt; "Hello World\n"})</code></pre>
83
+
84
+ <p>Append text to a TextEdit document:</p>
85
+
86
+ <pre><code># tell application "TextEdit" to make new paragraph &not;
87
+ # at end of text of document 1 &not;
88
+ # with properties {text:"Yesterday\nToday\nTomorrow\n"}
89
+
90
+ app('TextEdit').make(
91
+ :new =&gt; :paragraph,
92
+ :at =&gt; app.documents[1].text.end,
93
+ :with_data =&gt; "Yesterday\nToday\nTomorrow\n")</code></pre>
94
+
95
+ <p>Note that the <code>make</code> command's <code>at</code> parameter can be omitted for convenience, in which case the reference that the command is invoked on is used instead:</p>
96
+
97
+ <pre><code>app('TextEdit').documents[1].text.end.make(
98
+ :new =&gt; :paragraph,
99
+ :with_data =&gt; "Yesterday\nToday\nTomorrow\n")</code></pre>
100
+
101
+
102
+ <h3><code>duplicate</code></h3>
103
+
104
+ <p>Duplicate a folder to a disk, replacing an existing item if one exists:</p>
105
+
106
+ <pre><code># tell application "Finder" to &not;
107
+ # duplicate folder "Projects" of home to disk "Work" with replacing
108
+
109
+ app('Finder').home.folders['Projects'].duplicate(
110
+ :to =&gt; app.disks['Backup'], :replacing =&gt; true)</code></pre>
111
+
112
+
113
+ <h3><code>add</code></h3>
114
+
115
+ <p>Add every person with a known birthday to a group named "Birthdays":</p>
116
+
117
+ <pre><code># tell application "Address Book" to add &not;
118
+ # every person whose birth date is not missing value &not;
119
+ # to group "Birthdays"
120
+
121
+ app('Address Book').people[
122
+ its.birth_date.ne(:missing_value)
123
+ ].add(:to =&gt; app.groups['Birthdays'])</code></pre>
124
+
125
+
126
+
127
+ </div>
128
+
129
+ <!-- bottom navigation -->
130
+
131
+ <div class="footer">
132
+ <a href="11_applicationcommands.html">Previous</a> &bull;
133
+ <a href="index.html">Up</a> &bull;
134
+ <a href="13_performanceissues.html">Next</a>
135
+ </div>
136
+
137
+ </body>
138
+ </html>