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,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>
@@ -0,0 +1,192 @@
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 | 6. Classes and Enumerated Types</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="05_keywordconversion.html">Previous</a> &bull;
18
+ <a href="index.html">Up</a> &bull;
19
+ <a href="07_applicationobjects.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>6. Classes and Enumerated Types</h2>
33
+
34
+ <h3>Appscript keywords</h3>
35
+
36
+ <p>For your convenience, appscript represents Apple event type names and application-specific class and enumerator names as Ruby symbols. Examples:</p>
37
+
38
+ <pre><code># AEM-defined data types:
39
+ :boolean
40
+ :unicode_text
41
+ :list
42
+
43
+ # Application-defined class names:
44
+ :document
45
+ :window
46
+ :disk
47
+
48
+ # Application-defined enumerators:
49
+ :yes
50
+ :no
51
+ :ask</code></pre>
52
+
53
+ <p>Occasionally an application dictionary defines a type or enumerator without providing it with a corresponding name name. In these cases, the value will be represented as a raw <code>AEM::AEType</code> or <code>AEM::AEEnum</code> object instead of a symbol, e.g.:</p>
54
+
55
+ <pre><code>AEM::AEType.new('abcd')
56
+
57
+ AEM::AEEnum.new('xyz ')</code></pre>
58
+
59
+ <p>See the aem manual for more information on these lower-level objects, should you need to use them.</p>
60
+
61
+
62
+ <h3>Common AE types</h3>
63
+
64
+ <table width="100%" summary="AE-Ruby type mappings">
65
+ <thead>
66
+ <tr><th>AE type</th><th>appscript name</th><th>Ruby class</th></tr>
67
+ </thead>
68
+ <tbody>
69
+ <tr><td><code>typeNull</code></td><td><code>:null</code></td><td><code>NilClass</code></td></tr>
70
+ <tr><td><code>typeBoolean</code></td><td><code>:boolean</code></td><td><code>TrueClass/FalseClass</code></td></tr>
71
+ <tr><td><code>typeInteger</code></td><td><code>:integer</code></td><td><code>Fixnum/Bignum</code></td></tr>
72
+ <tr><td><code>typeFloat</code></td><td><code>:float</code></td><td><code>Float</code></td></tr>
73
+ <tr><td><code>typeChar</code> *</td><td><code>:string</code></td><td><code>String</code></td></tr>
74
+ <tr><td><code>typeStyledText</code> *</td><td><code>:styled_text</code></td><td><code>String</code></td></tr>
75
+ <tr><td><code>typeIntlText</code> *</td><td><code>:international_text</code></td><td><code>String</code></td></tr>
76
+ <tr><td><code>typeUnicodeText</code></td><td><code>:unicode_text</code></td><td><code>String</code></td></tr>
77
+ <tr><td><code>typeAEList</code></td><td><code>:list</code></td><td><code>Array</code></td></tr>
78
+ <tr><td><code>typeAERecord</code></td><td><code>:record</code></td><td><code>Hash</code></td></tr>
79
+ <tr><td><code>typeLongDateTime</code></td><td><code>:date</code></td><td><code>Time</code></td></tr>
80
+ <tr><td><code>typeAlias</code></td><td><code>:alias</code></td><td><code>MacTypes::Alias</code></td></tr>
81
+ <tr><td><code>typeFileURL</code></td><td><code>:file_url</code></td><td><code>MacTypes::FileURL</code></td></tr>
82
+ <tr><td><code>typeFSRef</code></td><td><code>:file_ref</code></td><td><code>MacTypes::FileURL</code></td></tr>
83
+ <tr><td><code>typeFSS</code> *</td><td><code>:file_specification</code></td><td><code>MacTypes::FileURL</code></td></tr>
84
+ <tr><td><code>typeObjectSpecifier</code></td><td><code>:reference</code></td><td><code>Appscript::Reference</code></td></tr>
85
+ <tr><td><code>typeInsertionLoc</code></td><td><code>:location_reference</code></td><td><code>Appscript::Reference</code></td></tr>
86
+ <tr><td><code>typeType</code></td><td><code>:type_class</code></td><td><code>Symbol</code></td></tr>
87
+ <tr><td><code>typeEnumerated</code></td><td><code>:enumerator</code></td><td><code>Symbol</code></td></tr>
88
+ <tr><td><small>unit types; e.g. </small> <code>typeFeet</code></td><td><small>unit names; e.g.</small> <code>:feet</code></td><td><code>MacTypes::Units</code></td></tr>
89
+ </tbody>
90
+ </table>
91
+
92
+ <p>(Note that types marked with '*' are officially deprecated and/or their use discouraged in Mac OS X. They remain supported to ensure backwards compatibility with older applications that may use them.)</p>
93
+
94
+
95
+ <h3>Type mapping notes</h3>
96
+
97
+ <p>While AEM-Ruby type conversions generally work quite seamlessly, it is sometimes useful to know some of the details involved, particularly when troubleshooting code that deals with older or buggy applications.</p>
98
+
99
+ <h4>Numbers</h4>
100
+
101
+ <p>When packing a <code>Bignum</code>, appscript will pack it either as a 32-bit integer (most preferred), 64-bit integer, or 64-bit float (least preferred), depending on the value's size.</p>
102
+
103
+
104
+ <h4>Strings (Ruby 1.8)</h4>
105
+
106
+ <p>Because Ruby 1.8 lacks native Unicode support, appscript unpacks all text-related AE types (<code>typeChar</code>, <code>typeUnicodeText</code>, etc.) as String instances containing UTF8-encoded data.</p>
107
+
108
+ <p>Appscript packs String instances containing UTF8-encoded data as the <code>typeUnicodeText</code> AE type. If the string does not contain valid UTF-8 data, a TypeError will be raised.</p>
109
+
110
+ <div class="hilitebox">
111
+ <p>You can enable a degree of UTF-8 support in Ruby's <code>String</code> class via the Jcode module (included in Ruby's standard library). To use Jcode, add the following lines to the start of your Ruby scripts, irb sessions, etc.:</p>
112
+ <pre><code>require "jcode"
113
+ $KCODE = "UTF8"</code></pre>
114
+
115
+ <p>This will improve the display of non-ASCII characters in irb, amongst other things.</p>
116
+
117
+ </div>
118
+
119
+ <p>Note that while <code>typeUnicodeText</code> is formally deprecated in Mac OS X 10.4+ in favour of <code>typeUTF8Text</code> and <code>typeUTF16ExternalRepresentation</code>, it is still in common usage so appscript continues to use it to ensure the broadest compatibility with existing scriptable applications.</p>
120
+
121
+
122
+ <h4>Strings (Ruby 1.9+)</h4>
123
+
124
+ <p>Each String instance in Ruby 1.9+ contains an <code>Encoding</code> instance that identifies the character set used. By default, appscript unpacks a text descriptors as a String instance containing UTF-8 encoded data and a UTF-8 Encoding, and encodes a string as UTF-8 prior to packing its data into a text descriptor. To disable this behavior for individual <code>Application</code> instances:</p>
125
+
126
+ <pre><code>some_app = Appscript.app('SomeApp')
127
+ some_app.AS_app_data.use_ascii_8bit
128
+ # Send commands here...</code></pre>
129
+
130
+ <p>Once invoked, Strings will be treated as UTF-8 encoded data with ASCII-8BIT Encoding; this is equivalent to the Ruby 1.8 behavior.</p>
131
+
132
+
133
+ <h4>Dates and Times</h4>
134
+
135
+ <p>Appscript packs Ruby <code>Time</code>, <code>Date</code> and <code>DateTime</code> instances as <code>typeLongDateTime</code> descriptors. (Note that AE dates does not include locale information.)</p>
136
+
137
+ <p>By default, <code>typeLongDateTime</code> descriptors are unpacked as Ruby <code>Time</code> instances. This is sufficient for most purposes; however, where the AEDesc contains a date value below or above the range supported by Ruby's <code>Time</code> class, an error will occur. To unpack dates as <code>DateTime</code> instances for individual <code>Application</code> instances:</p>
138
+
139
+ <pre><code>some_app = Appscript.app('SomeApp')
140
+ some_app.AS_app_data.use_datetime
141
+ # Send commands here...</code></pre>
142
+
143
+
144
+ <h4>Filesystem references</h4>
145
+
146
+ <p>The <code>typeAlias</code> AE type represents a filesystem object, and will continue to point to that object even if it's renamed or moved to another location on the same disk. The <code>typeFSRef</code> and <code>typeFileURL</code> types represent a filesystem location. Both can represent existing locations; the <code>typeFileURL</code> type can also be used to specify locations that don't already exist.</p>
147
+
148
+ <p>FSSpecs are also supported for sake of backwards-compatibility with older Carbon applications that sometimes still use them. They're deprecated in OS X, however, due to lack of proper Unicode and long filename support, and their use is discouraged.</p>
149
+
150
+ <p>Note that appscript unpacks FSRefs, FileURLs and FSSpecs as <code>MacTypes::FileURL</code> objects; users do not normally need to worry about this. <code>MacTypes::FileURL</code> objects created in Ruby will always pack as type <code>:FileURL</code>, however. See the <a href="../mactypes-manual/index.html">mactypes manual</a> for more information on <code>MacTypes::Alias</code> and <code>MacTypes::FileURL</code>.</p>
151
+
152
+ <p>When asking an application to coerce a return value into a file type you must specify the exact type (<code>:alias</code>, <code>:file_url</code>, <code>:file_ref</code>, or <code>:file_specification</code>) in the <code>get</code> command. e.g. To get a <code>MacTypes::FileURL</code> object for the current user's home folder, you would usually use:</p>
153
+
154
+ <pre><code>app('Finder').home.get(:result_type=&gt;:file_url)</code></pre>
155
+
156
+ <p>Also be aware that some applications may not support coercions to all AE file types; you'll need to experiment to find out which coercions are supported.</p>
157
+
158
+
159
+ <h4>Records</h4>
160
+
161
+ <p>The <code>typeAERecord</code> AE type is a struct-like data structure containing zero or more properties. Appscript represents AE records as Ruby hashes. The keys in this hash are usually symbols representing appscript-style property names, although they may also be <code>AEM::AEType</code> values or strings.</p>
162
+
163
+ <p>If a hash contains a <code>:class_</code> (or <code>AEM::AEType.new('pcls')</code>) key, appscript will pack the remaining items into an AE record, then coerce it to the type specified by this 'class' property. Similarly, when unpacking an record-like AEDesc with a custom type code, appscript will unpack it as a hash with the type represented by a <code>:class_</code> entry.</p>
164
+
165
+
166
+ <h4>Types and enumerators</h4>
167
+
168
+ <p>The <code>typeType</code> and <code>typeEnumerated</code> AE types are unpacked as Ruby symbols when the corresponding terminology is available, otherwise they are unpacked as <code>AEM::AEType</code> and <code>AEM::AEEnum</code> respectively.</p>
169
+
170
+
171
+ <h4>Unit types</h4>
172
+
173
+ <p>Unit type values are represented by instances of the <code>MacTypes::Units</code> class, e.g. <code>MacTypes::Units.inches(3.0)</code>. See the <a href="../mactypes-manual/index.html">mactypes manual</a> for more information.</p>
174
+
175
+
176
+ <h4>Miscellaneous types</h4>
177
+
178
+ <p>The Apple Event Manager defines many other AE types whose names and codes are defined by appscript for completeness. A few of these types are of occasional interest to users, the rest can simply be ignored. In most cases, values of these types will be represented by raw <code>AE::AEDesc</code> instances as appscript doesn't automatically convert them to native objects.</p>
179
+
180
+
181
+ </div>
182
+
183
+ <!-- bottom navigation -->
184
+
185
+ <div class="footer">
186
+ <a href="05_keywordconversion.html">Previous</a> &bull;
187
+ <a href="index.html">Up</a> &bull;
188
+ <a href="07_applicationobjects.html">Next</a>
189
+ </div>
190
+
191
+ </body>
192
+ </html>