rb-appscript 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/CHANGES +243 -0
  2. data/LICENSE +1 -0
  3. data/README +42 -0
  4. data/TODO +31 -0
  5. data/doc/aem-manual/01_introduction.html +48 -0
  6. data/doc/aem-manual/02_apioverview.html +89 -0
  7. data/doc/aem-manual/03_packingandunpackingdata.html +98 -0
  8. data/doc/aem-manual/04_references.html +401 -0
  9. data/doc/aem-manual/05_targettingapplications.html +133 -0
  10. data/doc/aem-manual/06_buildingandsendingevents.html +175 -0
  11. data/doc/aem-manual/07_findapp.html +54 -0
  12. data/doc/aem-manual/08_examples.html +85 -0
  13. data/doc/aem-manual/09_notes.html +41 -0
  14. data/doc/aem-manual/aemreferenceinheritance.gif +0 -0
  15. data/doc/aem-manual/full.css +21 -0
  16. data/doc/aem-manual/index.html +43 -0
  17. data/doc/appscript-manual/01_introduction.html +82 -0
  18. data/doc/appscript-manual/02_aboutappscripting.html +244 -0
  19. data/doc/appscript-manual/03_quicktutorial.html +154 -0
  20. data/doc/appscript-manual/04_gettinghelp.html +101 -0
  21. data/doc/appscript-manual/05_keywordconversion.html +91 -0
  22. data/doc/appscript-manual/06_classesandenums.html +174 -0
  23. data/doc/appscript-manual/07_applicationobjects.html +181 -0
  24. data/doc/appscript-manual/08_realvsgenericreferences.html +86 -0
  25. data/doc/appscript-manual/09_referenceforms.html +232 -0
  26. data/doc/appscript-manual/10_referenceexamples.html +142 -0
  27. data/doc/appscript-manual/11_applicationcommands.html +204 -0
  28. data/doc/appscript-manual/12_commandexamples.html +129 -0
  29. data/doc/appscript-manual/13_performanceissues.html +115 -0
  30. data/doc/appscript-manual/14_problemapps.html +193 -0
  31. data/doc/appscript-manual/15_notes.html +84 -0
  32. data/doc/appscript-manual/application_architecture.gif +0 -0
  33. data/doc/appscript-manual/application_architecture2.gif +0 -0
  34. data/doc/appscript-manual/finder_to_textedit_event.gif +0 -0
  35. data/doc/appscript-manual/full.css +21 -0
  36. data/doc/appscript-manual/index.html +49 -0
  37. data/doc/appscript-manual/relationships_example.gif +0 -0
  38. data/doc/appscript-manual/ruby_to_itunes_event.gif +0 -0
  39. data/doc/index.html +30 -0
  40. data/doc/mactypes-manual/index.html +216 -0
  41. data/doc/osax-manual/index.html +169 -0
  42. data/extconf.rb +54 -0
  43. data/misc/adobeunittypes.rb +14 -0
  44. data/misc/dump.rb +72 -0
  45. data/rb-appscript.gemspec +20 -0
  46. data/sample/AB_list_people_with_emails.rb +8 -0
  47. data/sample/Create_daily_iCal_todos.rb +72 -0
  48. data/sample/Hello_world.rb +9 -0
  49. data/sample/List_iTunes_playlist_names.rb +7 -0
  50. data/sample/Make_Mail_message.rb +29 -0
  51. data/sample/Open_file_in_TextEdit.rb +9 -0
  52. data/sample/Organize_Mail_messages.rb +57 -0
  53. data/sample/Print_folder_tree.rb +12 -0
  54. data/sample/Select_all_HTML_files.rb +8 -0
  55. data/sample/Set_iChat_status.rb +20 -0
  56. data/sample/Simple_Finder_GUI_Scripting.rb +14 -0
  57. data/sample/Stagger_Finder_windows.rb +21 -0
  58. data/sample/TextEdit_demo.rb +126 -0
  59. data/sample/iTunes_top40_to_html.rb +64 -0
  60. data/src/lib/_aem/aemreference.rb +1006 -0
  61. data/src/lib/_aem/codecs.rb +617 -0
  62. data/src/lib/_aem/connect.rb +100 -0
  63. data/src/lib/_aem/findapp.rb +83 -0
  64. data/src/lib/_aem/mactypes.rb +228 -0
  65. data/src/lib/_aem/send.rb +257 -0
  66. data/src/lib/_aem/typewrappers.rb +57 -0
  67. data/src/lib/_appscript/defaultterminology.rb +245 -0
  68. data/src/lib/_appscript/referencerenderer.rb +132 -0
  69. data/src/lib/_appscript/reservedkeywords.rb +107 -0
  70. data/src/lib/_appscript/terminology.rb +314 -0
  71. data/src/lib/aem.rb +216 -0
  72. data/src/lib/appscript.rb +830 -0
  73. data/src/lib/kae.rb +1484 -0
  74. data/src/lib/osax.rb +171 -0
  75. data/src/rbae.c +766 -0
  76. data/test/README +1 -0
  77. data/test/test_aemreference.rb +112 -0
  78. data/test/test_appscriptreference.rb +102 -0
  79. data/test/test_codecs.rb +159 -0
  80. data/test/test_findapp.rb +24 -0
  81. data/test/test_mactypes.rb +67 -0
  82. data/test/testall.sh +9 -0
  83. metadata +143 -0
@@ -0,0 +1,245 @@
1
+ #!/usr/local/bin/ruby
2
+ # Copyright (C) 2006 HAS.
3
+ # Released under MIT License.
4
+
5
+ module DefaultTerminology
6
+ # Defines built-in terminology available for any application. When constructing the terminology tables for a particular application, the Terminology module will duplicate these tables and then add application-specific terms to create the finished lookup tables.
7
+
8
+ require "aem"
9
+
10
+ Enums = {
11
+ 'yes ' => :yes,
12
+ 'no ' => :no,
13
+ 'ask ' => :ask,
14
+
15
+ 'case' => :case,
16
+ 'diac' => :diacriticals,
17
+ 'expa' => :expansion,
18
+ 'hyph' => :hyphens,
19
+ 'punc' => :punctuation,
20
+ 'whit' => :whitespace,
21
+ 'nume' => :numeric_strings,
22
+ 'rmte' => :application_responses,
23
+ }
24
+
25
+ Types = {
26
+ '****' => :anything,
27
+
28
+ 'bool' => :boolean,
29
+
30
+ 'shor' => :short_integer,
31
+ 'long' => :integer,
32
+ 'magn' => :unsigned_integer,
33
+ 'comp' => :double_integer,
34
+
35
+ 'fixd' => :fixed,
36
+ 'lfxd' => :long_fixed,
37
+ 'decm' => :decimal_struct,
38
+
39
+ 'sing' => :short_float,
40
+ 'doub' => :float,
41
+ 'exte' => :extended_float,
42
+ 'ldbl' => :float_128bit,
43
+
44
+ 'TEXT' => :string,
45
+ 'cstr' => :c_string,
46
+ 'pstr' => :pascal_string,
47
+ 'STXT' => :styled_text,
48
+ 'tsty' => :text_style_info,
49
+ 'styl' => :styled_clipboard_text,
50
+ 'encs' => :encoded_string,
51
+ 'psct' => :writing_code,
52
+ 'intl' => :international_writing_code,
53
+ 'itxt' => :international_text,
54
+ 'sutx' => :styled_unicode_text,
55
+ 'utxt' => :unicode_text,
56
+ 'utf8' => :utf8_text, # typeUTF8Text
57
+ 'ut16' => :utf16_text, # typeUTF16ExternalRepresentation
58
+
59
+ 'vers' => :version,
60
+ 'ldt ' => :date,
61
+ 'list' => :list,
62
+ 'reco' => :record,
63
+ 'rdat' => :data,
64
+ 'scpt' => :script,
65
+
66
+ 'insl' => :location_reference,
67
+ 'obj ' => :reference,
68
+
69
+ 'alis' => :alias,
70
+ 'fsrf' => :file_ref,
71
+ 'fss ' => :file_specification,
72
+ 'furl' => :file_url,
73
+
74
+ 'QDpt' => :point,
75
+ 'qdrt' => :bounding_rectangle,
76
+ 'fpnt' => :fixed_point,
77
+ 'frct' => :fixed_rectangle,
78
+ 'lpnt' => :long_point,
79
+ 'lrct' => :long_rectangle,
80
+ 'lfpt' => :long_fixed_point,
81
+ 'lfrc' => :long_fixed_rectangle,
82
+
83
+ 'EPS ' => :EPS_picture,
84
+ 'GIFf' => :GIF_picture,
85
+ 'JPEG' => :JPEG_picture,
86
+ 'PICT' => :PICT_picture,
87
+ 'TIFF' => :TIFF_picture,
88
+ 'cRGB' => :RGB_color,
89
+ 'tr16' => :RGB16_color,
90
+ 'tr96' => :RGB96_color,
91
+ 'cgtx' => :graphic_text,
92
+ 'clrt' => :color_table,
93
+ 'tpmm' => :pixel_map_record,
94
+
95
+ 'best' => :best,
96
+ 'type' => :type_class,
97
+ 'enum' => :enumerator,
98
+ 'prop' => :property,
99
+
100
+ # AEAddressDesc types
101
+
102
+ 'port' => :mach_port,
103
+ 'kpid' => :kernel_process_id,
104
+ 'bund' => :application_bundle_id,
105
+ 'psn ' => :process_serial_number,
106
+ 'sign' => :application_signature,
107
+ 'aprl' => :application_url,
108
+
109
+ # misc.
110
+
111
+ 'msng' => :missing_value,
112
+
113
+ 'pcls' => :class_,
114
+
115
+ 'null' => :null,
116
+
117
+ 'mLoc' => :machine_location,
118
+ 'mach' => :machine,
119
+
120
+ 'tdas' => :dash_style,
121
+ 'trot' => :rotation,
122
+
123
+ 'suin' => :suite_info,
124
+ 'gcli' => :class_info,
125
+ 'pinf' => :property_info,
126
+ 'elin' => :element_info,
127
+ 'evin' => :event_info,
128
+ 'pmin' => :parameter_info,
129
+
130
+ # unit types
131
+
132
+ 'cmtr' => :centimeters,
133
+ 'metr' => :meters,
134
+ 'kmtr' => :kilometers,
135
+ 'inch' => :inches,
136
+ 'feet' => :feet,
137
+ 'yard' => :yards,
138
+ 'mile' => :miles,
139
+
140
+ 'sqrm' => :square_meters,
141
+ 'sqkm' => :square_kilometers,
142
+ 'sqft' => :square_feet,
143
+ 'sqyd' => :square_yards,
144
+ 'sqmi' => :square_miles,
145
+
146
+ 'ccmt' => :cubic_centimeters,
147
+ 'cmet' => :cubic_meters,
148
+ 'cuin' => :cubic_inches,
149
+ 'cfet' => :cubic_feet,
150
+ 'cyrd' => :cubic_yards,
151
+
152
+ 'litr' => :liters,
153
+ 'qrts' => :quarts,
154
+ 'galn' => :gallons,
155
+
156
+ 'gram' => :grams,
157
+ 'kgrm' => :kilograms,
158
+ 'ozs ' => :ounces,
159
+ 'lbs ' => :pounds,
160
+
161
+ 'degc' => :degrees_Celsius,
162
+ 'degf' => :degrees_Fahrenheit,
163
+ 'degk' => :degrees_Kelvin,
164
+
165
+ # month and weekday
166
+
167
+ 'jan ' => :January,
168
+ 'feb ' => :February,
169
+ 'mar ' => :March,
170
+ 'apr ' => :April,
171
+ 'may ' => :May,
172
+ 'jun ' => :June,
173
+ 'jul ' => :July,
174
+ 'aug ' => :August,
175
+ 'sep ' => :September,
176
+ 'oct ' => :October,
177
+ 'nov ' => :November,
178
+ 'dec ' => :December,
179
+
180
+ 'sun ' => :Sunday,
181
+ 'mon ' => :Monday,
182
+ 'tue ' => :Tuesday,
183
+ 'wed ' => :Wednesday,
184
+ 'thu ' => :Thursday,
185
+ 'fri ' => :Friday,
186
+ 'sat ' => :Saturday,
187
+ }
188
+
189
+ #######
190
+ # TypeByCode and TypeByName tables are used to convert Ruby Symbols to and from AEDescs of typeType, typeEnum and typeProperty.
191
+
192
+ TypeByCode = Types.clone.update(Enums)
193
+
194
+ TypeByName = {}
195
+ Types.each { |code, name| TypeByName[name] = AEM::AEType.new(code) }
196
+ Enums.each { |code, name| TypeByName[name] = AEM::AEEnum.new(code) }
197
+
198
+ #######
199
+ # ReferenceByCode tables is used by ReferenceRenderer module to convert property and element four-char codes to human readable names
200
+ #
201
+ # ReferenceByName table is used to convert appscript-style references and commands to their aem equivalents
202
+
203
+ ReferenceByCode = {
204
+ 'pcls' => 'class_',
205
+ 'ID ' => 'id_',
206
+ }
207
+
208
+ ReferenceByName = {
209
+ :quit => [:command, ['aevtquit', {
210
+ :saving => 'savo',
211
+ }]],
212
+ :activate => [:command, ['miscactv', {
213
+ }]],
214
+ :run => [:command, ['aevtoapp', {
215
+ }]],
216
+ :launch => [:command, ['ascrnoop', {
217
+ }]],
218
+ :open => [:command, ['aevtodoc', {
219
+ }]],
220
+ :get => [:command, ['coregetd', {
221
+ }]],
222
+ :print => [:command, ['aevtpdoc', {
223
+ }]],
224
+ :class_ => [:property, 'pcls'],
225
+ :set => [:command, ['coresetd', {
226
+ :to => 'data',
227
+ }]],
228
+ :reopen => [:command, ['aevtrapp', {
229
+ }]],
230
+ :id_ => [:property, 'ID '],
231
+ :open_location => [:command, ['GURLGURL', {
232
+ :window => 'WIND',
233
+ }]],
234
+ }
235
+
236
+ #######
237
+ # DefaultCommands; used by Terminology._make_reference_table to check for any collisions between standard and application-defined commands where the command names are the same but the codes are different
238
+
239
+ DefaultCommands = {} # {'quit' => 'aevtquit', 'activate' => 'miscactv',...}
240
+ ReferenceByName.each do |name, info|
241
+ if info[0] == :command
242
+ DefaultCommands[name.to_s] = info[1][0]
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,132 @@
1
+ #!/usr/local/bin/ruby
2
+ # Copyright (C) 2006 HAS.
3
+ # Released under MIT License.
4
+
5
+ require "_aem/aemreference"
6
+
7
+
8
+ class ReferenceRenderer
9
+ # Generates string representations of appscript references from aem object specifiers.
10
+
11
+ private_class_method :new
12
+ attr_reader :result
13
+
14
+ def initialize(app_data)
15
+ @_app_data = app_data
16
+ @result = "AS"
17
+ end
18
+
19
+ def _format(val)
20
+ if val.is_a?(AEMReference::Base)
21
+ return ReferenceRenderer.render(@_app_data, val)
22
+ else
23
+ return val.inspect
24
+ end
25
+ end
26
+
27
+ def property(code)
28
+ name = @_app_data.reference_by_code.fetch('p'+code) { @_app_data.reference_by_code.fetch('e'+code) }
29
+ @result += ".#{name}"
30
+ return self
31
+ end
32
+
33
+ def elements(code)
34
+ name = @_app_data.reference_by_code.fetch('e'+code) { @_app_data.reference_by_code.fetch('p'+code) }
35
+ @result += ".#{name}"
36
+ return self
37
+ end
38
+
39
+ def by_name(name)
40
+ @result += "[#{_format(name)}]"
41
+ return self
42
+ end
43
+
44
+ def by_index(index)
45
+ @result += "[#{_format(index)}]"
46
+ return self
47
+ end
48
+
49
+ def by_id(id)
50
+ @result += ".ID(#{_format(id)})"
51
+ return self
52
+ end
53
+
54
+ def by_range(sel1, sel2)
55
+ @result += "[#{_format(sel1)}, #{_format(sel2)}]"
56
+ return self
57
+ end
58
+
59
+ def by_filter(sel)
60
+ @result += "[#{_format(sel)}]"
61
+ return self
62
+ end
63
+
64
+ def previous(sel)
65
+ @result += ".previous(#{_format(@_app_data.type_by_code[sel])})"
66
+ return self
67
+ end
68
+
69
+ def next(sel)
70
+ @result += ".next(#{_format(@_app_data.type_by_code[sel])})"
71
+ return self
72
+ end
73
+
74
+ def app
75
+ if @_app_data.path
76
+ @result += ".app(#{@_app_data.path.inspect})"
77
+ elsif @_app_data.pid
78
+ @result += ".app.by_pid(#{@_app_data.pid.inspect})"
79
+ elsif @_app_data.url
80
+ @result += ".app.by_url(#{@_app_data.url.inspect})"
81
+ else
82
+ @result += ".app.current"
83
+ end
84
+ return self
85
+ end
86
+
87
+ def con
88
+ @result += ".con"
89
+ return self
90
+ end
91
+
92
+ def its
93
+ @result += ".its"
94
+ return self
95
+ end
96
+
97
+ def method_missing(name, *args)
98
+ if args.length > 0
99
+ @result += ".#{name.to_s}(#{(args.map { |arg| arg.inspect }).join(', ')})"
100
+ else
101
+ @result += ".#{name.to_s}"
102
+ end
103
+ return self
104
+ end
105
+
106
+ # public
107
+
108
+ def ReferenceRenderer.render(app_data, aem_reference)
109
+ # Take an aem reference, e.g.:
110
+ #
111
+ # app.elements('docu').by_index(1).property('ctxt')
112
+ #
113
+ # and an AppData instance containing application's location and terminology,
114
+ # and render an appscript-style reference string, e.g.:
115
+ #
116
+ # "AS.app('/Applications/TextEdit.app').documents[1].text"
117
+ #
118
+ # Used by AS::Reference#to_s
119
+ #
120
+ f = new(app_data)
121
+ begin
122
+ aem_reference.AEM_resolve(f)
123
+ return f.result
124
+ rescue
125
+ return aem_reference.inspect
126
+ end
127
+ end
128
+
129
+ end
130
+
131
+
132
+
@@ -0,0 +1,107 @@
1
+ #!/usr/local/bin/ruby
2
+ # Copyright (C) 2006 HAS.
3
+ # Released under MIT License.
4
+
5
+ # This list is mirrored in ch.6 of the appscript manual and in py-appscript's osaterminology.makeidentifier module
6
+
7
+ ReservedKeywords = [
8
+ "==",
9
+ "===",
10
+ "=~",
11
+ "AS_aem_reference",
12
+ "AS_aem_reference=",
13
+ "AS_app_data",
14
+ "AS_app_data=",
15
+ "AS_resolve",
16
+ "ID",
17
+ "[]",
18
+ "__id__",
19
+ "__send__",
20
+ "_aem_application_class",
21
+ "_call",
22
+ "_resolve_range_boundary",
23
+ "_send_command",
24
+ "abort_transaction",
25
+ "after",
26
+ "and",
27
+ "any",
28
+ "before",
29
+ "by_creator",
30
+ "by_id",
31
+ "by_name",
32
+ "by_pid",
33
+ "by_url",
34
+ "class",
35
+ "clone",
36
+ "commands",
37
+ "contains",
38
+ "current",
39
+ "display",
40
+ "does_not_contain",
41
+ "does_not_end_with",
42
+ "does_not_start_with",
43
+ "dup",
44
+ "elements",
45
+ "end",
46
+ "end_transaction",
47
+ "ends_with",
48
+ "eq",
49
+ "eql?",
50
+ "equal?",
51
+ "extend",
52
+ "first",
53
+ "freeze",
54
+ "frozen?",
55
+ "ge",
56
+ "gt",
57
+ "hash",
58
+ "help",
59
+ "id",
60
+ "ignore",
61
+ "inspect",
62
+ "instance_eval",
63
+ "instance_of?",
64
+ "instance_variable_get",
65
+ "instance_variable_set",
66
+ "instance_variables",
67
+ "is_a?",
68
+ "is_in",
69
+ "is_not_in",
70
+ "keywords",
71
+ "kind_of?",
72
+ "last",
73
+ "launch",
74
+ "le",
75
+ "lt",
76
+ "method",
77
+ "method_missing",
78
+ "methods",
79
+ "middle",
80
+ "ne",
81
+ "next",
82
+ "nil?",
83
+ "not",
84
+ "object_id",
85
+ "or",
86
+ "parameters",
87
+ "previous",
88
+ "private_methods",
89
+ "properties",
90
+ "protected_methods",
91
+ "public_methods",
92
+ "respond_to?",
93
+ "result_type",
94
+ "send",
95
+ "singleton_methods",
96
+ "start",
97
+ "start_transaction",
98
+ "starts_with",
99
+ "taint",
100
+ "tainted?",
101
+ "timeout",
102
+ "to_a",
103
+ "to_s",
104
+ "type",
105
+ "untaint",
106
+ "wait_reply",
107
+ ]