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,167 @@
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 | 3. Quick Tutorial</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="02_aboutappscripting.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="04_gettinghelp.html">Next</a>
20
+
21
+ <span>
22
+ <strong><a href="../appscript-manual/index.html">appscript</a></strong> /
23
+ <a href="../mactypes-manual/index.html">mactypes</a> /
24
+ <a href="../osax-manual/index.html">osax</a> /
25
+ <a href="../aem-manual/index.html">aem</a>
26
+ </span>
27
+ </div>
28
+
29
+ <!-- content -->
30
+ <div id="content">
31
+
32
+ <h2>3. Quick Tutorial</h2>
33
+
34
+ <p>The following tutorial provides a practical taste of application scripting with appscript. Later chapters cover the technical details of appscript usage that are mostly skimmed over here.</p>
35
+
36
+ <h3>'Hello World' tutorial</h3>
37
+
38
+ <p>This tutorial uses appscript, TextEdit and the interactive command line Ruby interpreter to perform a simple 'Hello World' exercise.</p>
39
+
40
+ <p class="hilitebox">Caution: It is recommended that you do not have any other documents open in TextEdit during this tutorial, as accidental modifications are easy to make and changes to existing documents are not undoable.</p>
41
+
42
+ <p>To begin, launch Terminal.app and type <tt>irb</tt> followed by a newline to launch the interactive Ruby interpreter:</p>
43
+
44
+ <pre><code>brian% irb
45
+ irb(main):001:0&gt;</code></pre>
46
+
47
+ <h4>Target TextEdit</h4>
48
+
49
+ <p>The first step is to import the appscript module, <code>Appscript</code>, which provides the following functions and classes: <code>app</code>, <code>con</code>, <code>its</code>, <code>CommandError</code> and <code>ApplicationNotFoundError</code>.</p>
50
+
51
+ <pre><code>irb&gt; require "appscript"
52
+ =&gt; true
53
+ irb&gt; include Appscript
54
+ =&gt; Object</code></pre>
55
+
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
+
58
+ <pre><code>irb&gt; te = app('TextEdit')
59
+ =&gt; app("/Applications/TextEdit.app")</code></pre>
60
+
61
+ <p>The application may be identified by name, path, bundle ID, creator type, Unix process id, or, if running remotely, URL. If the application is identified by name, path, bundle ID or creator type and is not already running, it will be launched automatically for you.</p>
62
+
63
+ <h4>Create a new document</h4>
64
+
65
+ <p>First, create a new TextEdit document by making a new <code>document</code> object. This is done using the <code>make</code> command, passing it a single keyword parameter, <code>:new =&gt; :document</code>, indicating the type of object to create:</p>
66
+
67
+ <pre><code>irb&gt; te.make(:new =&gt; :document)
68
+ =&gt; app("/Applications/TextEdit.app").documents[1]</code></pre>
69
+
70
+ <p>Notice that keyword parameters are specified as an inline Hash with symbols as keys. The <a href="11_applicationcommands.html">Application Commands</a> chapter will discuss appscript's command syntax in more detail.</p>
71
+
72
+ <p>Because <code>document</code> objects are always elements of the root <code>application</code> class, applications such as TextEdit can usually infer the location at which the new <code>document</code> object should appear. At other times, you need to supply an <code>at</code> parameter that indicates the desired location.</p>
73
+
74
+ <p>As you can see, the <code>make</code> command returns a reference identifying the newly-created object. This reference can be assigned to a variable for easy reuse. Use the <code>make</code> command to create another document, this time assigning its result to a variable, <code>doc</code>:</p>
75
+
76
+ <pre><code>irb&gt; doc = te.make(:new =&gt; :document)
77
+ =&gt; app("/Applications/TextEdit.app").documents[1]</code></pre>
78
+
79
+ <h4>Set the document's content</h4>
80
+
81
+ <p>The next step is to set the document's content to the string <code>"Hello World"</code>. Every TextEdit document has a property, <code>text</code>, that represents the entire text of the document. This property is both readable and writeable, allowing you to retrieve and/or modify the document's textual content as unstyled unicode text.</p>
82
+
83
+ <p>Setting a property's value is done using the <code>set</code> command. The <code>set</code> command is exposed as a method of the root <code>application</code> class and has two parameters: a direct (positional) parameter containing reference to the property (or properties) to be modified, and a keyword parameter, <code>to</code>, containing the new value. In this case, the direct parameter is a reference to the new document's <code>text</code> property, <code>doc.text</code>, and the <code>to</code> parameter is the string <code>"Hello World"</code>:</p>
84
+
85
+ <pre><code>irb&gt; te.set(doc.text, :to =&gt; 'Hello World')
86
+ =&gt; nil</code></pre>
87
+
88
+ <p>The front TextEdit document should now contain the text '<tt>Hello World</tt>'.</p>
89
+
90
+ <p>Because the above expression is a bit unwieldy to write, appscript allows it to be written in a more elegant OO-like format as a special case, where the <code>set</code> command is called upon the reference and the <code>to</code> keyword is omitted:</p>
91
+
92
+ <pre><code>doc.text.set('Hello World')</code></pre>
93
+
94
+ <p>Appscript converts this second form to the first form internally, so the end result is exactly the same. Appscript supports several such special cases, and these are described in the <a href="11_applicationcommands.html">Application Commands</a> chapter. Using these special cases produces more elegant, readable source code, and is recommended.</p>
95
+
96
+ <h4>Get the document's content</h4>
97
+
98
+ <p>Retrieving the document's text is done using the <code>get</code> command:</p>
99
+
100
+ <pre><code>irb&gt; doc.text.get
101
+ =&gt; "Hello World"</code></pre>
102
+
103
+ <p>This may seem counter-intuitive if you're used to dealing with AppleScript or object-oriented Ruby references, where evaluating a literal reference returns the <em>value</em> identified by that reference. However, always remember that appscript 'references' are really first-class query objects: while the syntax may look familiar, any similarity is purely superficial. For example, when evaluating the literal reference:</p>
104
+
105
+ <pre><code>te.documents[1].text</code></pre>
106
+
107
+ <p>the result is another reference, <code>app("/Applications/TextEdit.app").documents[1].text</code>, not the value being referenced (<tt>'Hello World'</tt>). To get the value being referenced, you have to pass the reference as the direct argument to TextEdit's <code>get</code> command:</p>
108
+
109
+ <pre><code>irb&gt; te.get(doc.text)
110
+ =&gt; "Hello World!"</code></pre>
111
+
112
+ <p>As usual, appscript provides an alternative convenience form that allow this to be written as:</p>
113
+
114
+ <pre><code>doc.text.get</code></pre>
115
+
116
+
117
+ <p>Depending on what sort of attribute(s) the reference identifies, <code>get</code> may return a primitive value (number, string, list, dict, etc.), or it may return another reference, or list of references, e.g.:</p>
118
+
119
+ <pre><code>irb&gt; doc.text.get
120
+ =&gt; "Hello World!"
121
+ irb&gt; te.documents[1].get
122
+ =&gt; app("/Applications/TextEdit.app").documents[1]
123
+ irb&gt; te.documents.get
124
+ =&gt; [app("/Applications/TextEdit.app").documents[1],
125
+ app("/Applications/TextEdit.app").documents[2]]
126
+ irb&gt; te.documents.text.get
127
+ =&gt; ["Hello World", ""]</code></pre>
128
+
129
+
130
+
131
+ <h4>More on <code>make</code></h4>
132
+
133
+ <p>The above exercise uses two commands to create a new TextEdit document containing the text '<tt>Hello World</tt>'. It is also possible to perform both operations using the <code>make</code> command alone by passing the value for the new document's <code>text</code> property via the <code>make</code> command's optional <code>with_properties</code> parameter:</p>
134
+
135
+ <pre><code>irb&gt; te.make(:new =&gt; :document, :with_properties =&gt; {:text =&gt; 'Hello World'})
136
+ =&gt; app('/Applications/TextEdit.app').documents[1]</code></pre>
137
+
138
+ <p>Incidentally, you might note that every time the <code>make</code> command is used, it returns a reference to document <em>1</em>. TextEdit identifies its <code>document</code> objects according to the stacking order of their windows, with document 1 being frontmost. When the window stacking order changes, whether as a result of a script command or GUI-based interaction, so does the order of their corresponding <code>document</code> objects. This means that a previously created reference such as <code>app('/Applications/TextEdit.app').documents[1]</code> may now identify a different <code>document</code> object to before! Some applications prefer to return references that identify objects by name or unique ID rather than index to reduce or eliminate the potential for confusion, but it's an issue you should be aware of, particularly with long-running scripts where there is greater opportunity for unexpected third-party interactions to throw a spanner in the works.</p>
139
+
140
+
141
+ <h4>More on manipulating <code>text</code></h4>
142
+
143
+ <p>In addition to getting and setting a document's entire text by applying <code>get</code> and <code>set</code> commands to <code>text</code> property, it's also possible to manipulate selected sections of a document's text directly. TextEdit's <code>text</code> property contains a <code>text</code> object, which in turn has <code>character</code>, <code>word</code> and <code>paragraph</code> elements, all of which can be manipulated using a variety of commands: <code>get</code>, <code>set</code>, <code>make</code>, <code>move</code>, <code>delete</code>, etc. For example, to set the size of the first character of every paragraph of the front document to 24pt:</p>
144
+
145
+ <pre><code>te.documents[1].text.paragraphs.size.set(24)</code></pre>
146
+
147
+ <p>Or to insert a new paragraph at the end of the document:</p>
148
+
149
+ <pre><code>te.make(
150
+ :new =&gt; :paragraph,
151
+ :with_data =&gt; "Hello Again, World\n",
152
+ :at =&gt; te.documents[1].text.paragraphs.end)</code></pre>
153
+
154
+
155
+
156
+ </div>
157
+
158
+ <!-- bottom navigation -->
159
+
160
+ <div class="footer">
161
+ <a href="02_aboutappscripting.html">Previous</a> &bull;
162
+ <a href="index.html">Up</a> &bull;
163
+ <a href="04_gettinghelp.html">Next</a>
164
+ </div>
165
+
166
+ </body>
167
+ </html>
@@ -0,0 +1,188 @@
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 | 4. Getting Help</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="03_quicktutorial.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="05_keywordconversion.html">Next</a>
20
+
21
+ <span>
22
+ <strong><a href="../appscript-manual/index.html">appscript</a></strong> /
23
+ <a href="../mactypes-manual/index.html">mactypes</a> /
24
+ <a href="../osax-manual/index.html">osax</a> /
25
+ <a href="../aem-manual/index.html">aem</a>
26
+ </span>
27
+ </div>
28
+
29
+ <!-- content -->
30
+ <div id="content">
31
+
32
+ <h2>4. Getting Help</h2>
33
+
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
+
36
+
37
+
38
+ <h3>ASDictionary</h3>
39
+
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
+
42
+
43
+
44
+ <h3>Built-in <code>help</code> method</h3>
45
+
46
+ <p>Appscript's <code>Application</code> and <code>Reference</code> classes include a powerful interactive help system that allows you to explore applications' scripting interfaces from within running scripts and Ruby's interactive <code>irb</code> interpreter. The <code>help</code> method can provide information on any suite, class, command or reference, and display the inheritance and relationships for a selected class or the entire application.</p>
47
+
48
+ <div class="hilitebox">Note that rb-appscript's built-in help system is only available when ASDictionary 0.9.0 or later is installed. If ASDictionary isn't available or is too old, invoking <code>help</code> will simply result in a "No help available" message and the script will continue to run as normal.</div>
49
+
50
+ <p>Built-in help is invoked by calling an <code>app</code> object's <code>help</code> method, optionally passing it a string indicating the type of information you want. The resulting help message is printed to <code>stderr</code> and script execution continues as normal. For example, to view the help system's own help, call the <code>help</code> method with <code>'-h'</code> as its argument:</p>
51
+
52
+ <pre><code>app('TextEdit').help('-h')</code></pre>
53
+
54
+ <p>To print a description of any class or command or view inheritance and relationships, pass the <code>help</code> method a help string containing one or more of the following options:</p>
55
+
56
+ <dl>
57
+ <dt>-h</dt>
58
+ <dd>show help</dd>
59
+ <dt>-o</dt>
60
+ <dd>overview of all suites, classes and commands</dd>
61
+ <dt>-k</dt>
62
+ <dd>list all built-in keywords (type names)</dd>
63
+ <dt>-u [suite-name]</dt>
64
+ <dd>summary of named suite or all suites</dd>
65
+ <dt>-t [class-or-command-name]</dt>
66
+ <dd>terminology for named class/command or current reference</dd>
67
+ <dt>-i [class-name]</dt>
68
+ <dd>inheritance tree for named class or all classes</dd>
69
+ <dt>-r [class-name]</dt>
70
+ <dd>one-to-one and one-to-many relationships for named class or current reference</dd>
71
+ <dt>-s [property-or-element-name]</dt>
72
+ <dd>values of properties and elements of object(s) currently referenced</dd>
73
+ </dl>
74
+
75
+ <p>Arguments (shown in brackets) are optional. Additional information on usage is available via <code>help('-h')</code>.</p>
76
+
77
+ <p>Examples:</p>
78
+
79
+ <pre><code>app('Finder').help('-o')
80
+ app('Finder').help('-t window')
81
+ app('Finder').files.help # same as help('-t')
82
+ app('Finder').help('-d item -r folder -i container')
83
+ app('Finder').files.help('-s')</code></pre>
84
+
85
+
86
+ <p>To print detailed information on a specific reference, call its <code>help</code> method without arguments. Examples:</p>
87
+
88
+ <pre><code>app('TextEdit').help
89
+ app('TextEdit').version.help
90
+ app('TextEdit').documents.help</code></pre>
91
+
92
+
93
+ <p>To print detailed information on a specific command, call the <code>help</code> method on an application or reference object with the <code>-t</code> option followed by the command's name. Examples:</p>
94
+
95
+ <pre><code>app('TextEdit').help('-t open')
96
+ app('TextEdit').documents.help('-t count -t close')</code></pre>
97
+
98
+ <div class="hilitebox">
99
+ <p>Tip: <code>help</code> calls can safely be inserted at any point in a reference without disrupting your script's execution:</p>
100
+
101
+ <pre><code>c = app('TextEdit')<strong>.help.help('-o -i -s')</strong>.documents.<strong>help</strong>[1]<strong>.help</strong>.count</code></pre>
102
+ </div>
103
+
104
+
105
+
106
+ <h3>Introspection</h3>
107
+
108
+ <p>In addition to supporting Ruby's standard <code>#methods</code> and <code>#respond_to?</code> methods, appscript's <code>Application</code> and <code>Reference</code> classes also define several instance methods for obtaining information on the target application: </p>
109
+
110
+ <dl>
111
+ <dt><code>properties</code></dt>
112
+ <dd>Returns a list of all property names.</dd>
113
+
114
+ <dt><code>elements</code></dt>
115
+ <dd>Returns a list of all element names.</dd>
116
+
117
+ <dt><code>commands</code></dt>
118
+ <dd>Returns a list of all command names.</dd>
119
+
120
+ <dt><code>keywords</code></dt>
121
+ <dd>Returns a list of all class, enumerator, type and property names.</dd>
122
+
123
+ <dt><code>parameters(commandName)</code></dt>
124
+ <dd>Takes a command's name as string and returns the names of its parameters.</dd>
125
+ </dl>
126
+
127
+ <p>As with Ruby's <code>Object#methods</code>, all of these methods return a list of strings.</p>
128
+
129
+ <p>Examples</p>
130
+
131
+ <pre><code>te = app('TextEdit')
132
+
133
+ p te.commands
134
+ # ["activate", "close", "count", "delete", "duplicate", "exists", ...]
135
+
136
+ p te.parameters('make')
137
+ # ["at", "new", "with_data", "with_properties"]</code></pre>
138
+
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
+
159
+ <h3>Notes</h3>
160
+
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>
162
+
163
+
164
+ <h3>Other sources of help</h3>
165
+
166
+ <ul>
167
+ <li>The <code>sample</code> folder contains example scripts demonstrating a range of common tasks.</li>
168
+
169
+ <li>Refer to any scripting documentation and example scripts supplied by the application developer.</li>
170
+
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>
172
+
173
+ <li>The <a href="http://appscript.sourceforge.net">appscript website</a> has links to mailing lists and other general resources.</li>
174
+ </ul>
175
+
176
+
177
+ </div>
178
+
179
+ <!-- bottom navigation -->
180
+
181
+ <div class="footer">
182
+ <a href="03_quicktutorial.html">Previous</a> &bull;
183
+ <a href="index.html">Up</a> &bull;
184
+ <a href="05_keywordconversion.html">Next</a>
185
+ </div>
186
+
187
+ </body>
188
+ </html>
@@ -0,0 +1,106 @@
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 | 5. Keyword Conversion</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="04_gettinghelp.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="06_classesandenums.html">Next</a>
20
+
21
+ <span>
22
+ <strong><a href="../appscript-manual/index.html">appscript</a></strong> /
23
+ <a href="../mactypes-manual/index.html">mactypes</a> /
24
+ <a href="../osax-manual/index.html">osax</a> /
25
+ <a href="../aem-manual/index.html">aem</a>
26
+ </span>
27
+ </div>
28
+
29
+ <!-- content -->
30
+ <div id="content">
31
+
32
+ <h2>5. Keyword Conversion</h2>
33
+
34
+ <h3>Keyword conversion</h3>
35
+
36
+ <p>Because application terminology resources specify AppleScript-style keywords for class, property, command, etc. names, appscript uses the following rules to translate these keywords to legal Ruby identifiers:</p>
37
+
38
+ <ul>
39
+ <li>Characters a-z, A-Z, 0-9 and underscores (_) are preserved.</li>
40
+
41
+ <li>Spaces, hyphens (-) and forward slashes (/) are replaced with underscores.</li>
42
+
43
+ <li>Ampersands (&amp;) are replaced by the word 'and'.</li>
44
+
45
+ <li>All other characters are converted to 0x00-style hexadecimal representations.</li>
46
+
47
+ <li>Names that begin with '_' or 'AS_' have an underscore appended.</li>
48
+
49
+ <li>Names that match the methods already defined on appscript's Application and Reference classes have an underscore appended. The reserved method names are:
50
+
51
+ <pre><code>abort_transaction ignore
52
+ after inspect
53
+ and instance_eval
54
+ any instance_variable_get
55
+ before instance_variable_set
56
+ begin_transaction instance_variables
57
+ beginning is_in
58
+ begins_with is_not_in
59
+ by_aem_app keywords
60
+ by_creator last
61
+ by_id launch
62
+ by_name le
63
+ by_pid lt
64
+ by_url method
65
+ class method_missing
66
+ clone methods
67
+ commands middle
68
+ contains ne
69
+ current next
70
+ display not
71
+ does_not_begin_with object_id
72
+ does_not_contain or
73
+ does_not_end_with parameters
74
+ dup previous
75
+ elements private_methods
76
+ end properties
77
+ end_transaction protected_methods
78
+ ends_with public_methods
79
+ eq result_type
80
+ extend send
81
+ first singleton_methods
82
+ freeze taint
83
+ ge timeout
84
+ gt to_a
85
+ hash to_s
86
+ help type
87
+ ID untaint
88
+ id wait_reply</code></pre>
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>
92
+ </ul>
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
+
97
+ <!-- bottom navigation -->
98
+
99
+ <div class="footer">
100
+ <a href="04_gettinghelp.html">Previous</a> &bull;
101
+ <a href="index.html">Up</a> &bull;
102
+ <a href="06_classesandenums.html">Next</a>
103
+ </div>
104
+
105
+ </body>
106
+ </html>