rb-scpt 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rb-scpt-1.0.1.gem +0 -0
  3. data/extconf.rb +12 -12
  4. data/rb-scpt.gemspec +10 -10
  5. data/sample/AB_export_vcard.rb +16 -16
  6. data/sample/AB_list_people_with_emails.rb +4 -4
  7. data/sample/Add_iCal_event.rb +12 -12
  8. data/sample/Create_daily_iCal_todos.rb +28 -28
  9. data/sample/Export_Address_Book_phone_numbers.rb +52 -52
  10. data/sample/Hello_world.rb +10 -10
  11. data/sample/List_iTunes_playlist_names.rb +3 -3
  12. data/sample/Make_Mail_message.rb +24 -24
  13. data/sample/Open_file_in_TextEdit.rb +5 -5
  14. data/sample/Organize_Mail_messages.rb +46 -46
  15. data/sample/Print_folder_tree.rb +5 -5
  16. data/sample/Select_all_HTML_files.rb +6 -6
  17. data/sample/Set_iChat_status.rb +12 -12
  18. data/sample/Simple_Finder_GUI_Scripting.rb +6 -6
  19. data/sample/Stagger_Finder_windows.rb +9 -9
  20. data/sample/TextEdit_demo.rb +71 -71
  21. data/sample/iTunes_top40_to_html.rb +28 -30
  22. data/src/SendThreadSafe.c +293 -293
  23. data/src/SendThreadSafe.h +108 -108
  24. data/src/lib/_aem/aemreference.rb +997 -998
  25. data/src/lib/_aem/codecs.rb +609 -610
  26. data/src/lib/_aem/connect.rb +197 -197
  27. data/src/lib/_aem/encodingsupport.rb +67 -67
  28. data/src/lib/_aem/findapp.rb +75 -75
  29. data/src/lib/_aem/mactypes.rb +241 -242
  30. data/src/lib/_aem/send.rb +268 -268
  31. data/src/lib/_aem/typewrappers.rb +52 -52
  32. data/src/lib/_appscript/defaultterminology.rb +266 -266
  33. data/src/lib/_appscript/referencerenderer.rb +230 -233
  34. data/src/lib/_appscript/reservedkeywords.rb +106 -106
  35. data/src/lib/_appscript/safeobject.rb +125 -125
  36. data/src/lib/_appscript/terminology.rb +448 -449
  37. data/src/lib/aem.rb +238 -238
  38. data/src/lib/kae.rb +1487 -1487
  39. data/src/lib/osax.rb +647 -647
  40. data/src/lib/rb-scpt.rb +1065 -1065
  41. data/src/rbae.c +595 -595
  42. data/test/test_aemreference.rb +104 -107
  43. data/test/test_appscriptcommands.rb +131 -134
  44. data/test/test_appscriptreference.rb +96 -99
  45. data/test/test_codecs.rb +166 -168
  46. data/test/test_findapp.rb +13 -16
  47. data/test/test_mactypes.rb +70 -72
  48. data/test/test_osax.rb +46 -48
  49. data/test/testall.sh +4 -4
  50. metadata +8 -7
data/src/rbae.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * rb-appscript
3
3
  *
4
- * ae -- a low-level API providing a basic Ruby wrapper around the various
4
+ * ae -- a low-level API providing a basic Ruby wrapper around the various
5
5
  * Apple Event Manager, Process Manager and Launch Services APIs used by aem
6
6
  *
7
7
  * Thanks to:
@@ -21,7 +21,7 @@ static VALUE cMacOSError;
21
21
 
22
22
  // Note: AEDescs need extra wrapping to avoid nasty problems with Ruby's Data_Wrap_Struct.
23
23
  struct rbAE_AEDescWrapper {
24
- AEDesc desc;
24
+ AEDesc desc;
25
25
  };
26
26
 
27
27
  // (these two macros are basically cribbed from RubyAEOSA's aedesc.c)
@@ -30,9 +30,9 @@ struct rbAE_AEDescWrapper {
30
30
 
31
31
  // Event handling
32
32
  #if __LP64__
33
- // SRefCon typedefed as void * by system headers
33
+ // SRefCon typedefed as void * by system headers
34
34
  #else
35
- typedef long SRefCon;
35
+ typedef long SRefCon;
36
36
  #endif
37
37
 
38
38
  AEEventHandlerUPP upp_GenericEventHandler;
@@ -55,17 +55,17 @@ AECoercionHandlerUPP upp_GenericCoercionHandler;
55
55
  * just results in unexpected errors. (I've not quite figured out how to implement an
56
56
  * Exception class in C that constructs correctly in both C and Ruby. Not serious, since
57
57
  * nobody else needs to raise MacOSErrors - just a bit irritating.)
58
- */
58
+ */
59
59
 
60
60
  static void
61
61
  rbAE_raiseMacOSError(const char *description, OSErr number)
62
62
  {
63
- VALUE errObj;
64
-
65
- errObj = rb_funcall(cMacOSError, rb_intern("new"), 0);
66
- rb_iv_set(errObj, "@number", INT2NUM(number)); // returns the OS error number
67
- rb_iv_set(errObj, "@description", rb_str_new2(description)); // troubleshooting info
68
- rb_exc_raise(errObj);
63
+ VALUE errObj;
64
+
65
+ errObj = rb_funcall(cMacOSError, rb_intern("new"), 0);
66
+ rb_iv_set(errObj, "@number", INT2NUM(number)); // returns the OS error number
67
+ rb_iv_set(errObj, "@description", rb_str_new2(description)); // troubleshooting info
68
+ rb_exc_raise(errObj);
69
69
  }
70
70
 
71
71
 
@@ -75,10 +75,10 @@ rbAE_raiseMacOSError(const char *description, OSErr number)
75
75
  static VALUE
76
76
  rbAE_MacOSError_inspect(VALUE self)
77
77
  {
78
- char s[32];
79
-
80
- sprintf(s, "#<AE::MacOSError %li>", (long)NUM2INT(rb_iv_get(self, "@number")));
81
- return rb_str_new2(s);
78
+ char s[32];
79
+
80
+ sprintf(s, "#<AE::MacOSError %li>", (long)NUM2INT(rb_iv_get(self, "@number")));
81
+ return rb_str_new2(s);
82
82
  }
83
83
 
84
84
 
@@ -88,20 +88,20 @@ rbAE_MacOSError_inspect(VALUE self)
88
88
  static DescType
89
89
  rbStringToDescType(VALUE obj)
90
90
  {
91
- if (rb_obj_is_kind_of(obj, rb_cString) && RSTRING_LEN(obj) == 4) {
92
- return CFSwapInt32HostToBig(*(DescType *)(RSTRING_PTR(obj)));
93
- } else {
94
- rb_raise(rb_eArgError, "Not a four-char-code string.");
95
- }
91
+ if (rb_obj_is_kind_of(obj, rb_cString) && RSTRING_LEN(obj) == 4) {
92
+ return CFSwapInt32HostToBig(*(DescType *)(RSTRING_PTR(obj)));
93
+ } else {
94
+ rb_raise(rb_eArgError, "Not a four-char-code string.");
95
+ }
96
96
  }
97
97
 
98
98
  static VALUE
99
99
  rbDescTypeToString(DescType descType)
100
100
  {
101
- char s[4];
102
-
103
- *(DescType*)s = CFSwapInt32HostToBig(descType);
104
- return rb_str_new(s, 4);
101
+ char s[4];
102
+
103
+ *(DescType*)s = CFSwapInt32HostToBig(descType);
104
+ return rb_str_new(s, 4);
105
105
  }
106
106
 
107
107
  /*******/
@@ -109,19 +109,19 @@ rbDescTypeToString(DescType descType)
109
109
  static void
110
110
  rbAE_freeAEDesc(struct rbAE_AEDescWrapper *p)
111
111
  {
112
- AEDisposeDesc(&(p->desc));
113
- free(p);
112
+ AEDisposeDesc(&(p->desc));
113
+ free(p);
114
114
  }
115
115
 
116
116
  static VALUE
117
117
  rbAE_wrapAEDesc(const AEDesc *desc)
118
118
  {
119
- struct rbAE_AEDescWrapper *wrapper;
120
-
121
- // Found out how to wrap AEDescs so Ruby wouldn't crash by reading RubyAEOSA's aedesc.c
122
- wrapper = malloc(sizeof(struct rbAE_AEDescWrapper));
123
- wrapper->desc = *desc;
124
- return Data_Wrap_Struct(cAEDesc, 0, rbAE_freeAEDesc, wrapper);
119
+ struct rbAE_AEDescWrapper *wrapper;
120
+
121
+ // Found out how to wrap AEDescs so Ruby wouldn't crash by reading RubyAEOSA's aedesc.c
122
+ wrapper = malloc(sizeof(struct rbAE_AEDescWrapper));
123
+ wrapper->desc = *desc;
124
+ return Data_Wrap_Struct(cAEDesc, 0, rbAE_freeAEDesc, wrapper);
125
125
  }
126
126
 
127
127
  /*******/
@@ -131,17 +131,17 @@ rbAE_wrapAEDesc(const AEDesc *desc)
131
131
  static void
132
132
  rbAE_freeBorrowedAEDesc(struct rbAE_AEDescWrapper *p)
133
133
  {
134
- free(p);
134
+ free(p);
135
135
  }
136
136
 
137
137
  static VALUE
138
138
  rbAE_wrapBorrowedAEDesc(const AEDesc *desc)
139
139
  {
140
- struct rbAE_AEDescWrapper *wrapper;
141
-
142
- wrapper = malloc(sizeof(struct rbAE_AEDescWrapper));
143
- wrapper->desc = *desc;
144
- return Data_Wrap_Struct(cAEDesc, 0, rbAE_freeBorrowedAEDesc, wrapper);
140
+ struct rbAE_AEDescWrapper *wrapper;
141
+
142
+ wrapper = malloc(sizeof(struct rbAE_AEDescWrapper));
143
+ wrapper->desc = *desc;
144
+ return Data_Wrap_Struct(cAEDesc, 0, rbAE_freeBorrowedAEDesc, wrapper);
145
145
  }
146
146
 
147
147
  /**********************************************************************/
@@ -150,81 +150,81 @@ rbAE_wrapBorrowedAEDesc(const AEDesc *desc)
150
150
  static VALUE
151
151
  rbAE_AEDesc_new(VALUE class, VALUE type, VALUE data)
152
152
  {
153
- OSErr err = noErr;
154
- AEDesc desc;
155
-
156
- Check_Type(data, T_STRING);
157
- err = AECreateDesc(rbStringToDescType(type),
158
- RSTRING_PTR(data), RSTRING_LEN(data),
159
- &desc);
160
- if (err != noErr) rbAE_raiseMacOSError("Can't create AEDesc.", err);
161
- return rbAE_wrapAEDesc(&desc);
153
+ OSErr err = noErr;
154
+ AEDesc desc;
155
+
156
+ Check_Type(data, T_STRING);
157
+ err = AECreateDesc(rbStringToDescType(type),
158
+ RSTRING_PTR(data), RSTRING_LEN(data),
159
+ &desc);
160
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AEDesc.", err);
161
+ return rbAE_wrapAEDesc(&desc);
162
162
  }
163
163
 
164
164
 
165
165
  static VALUE
166
166
  rbAE_AEDesc_newList(VALUE class, VALUE isRecord)
167
167
  {
168
- OSErr err = noErr;
169
- AEDesc desc;
170
-
171
- err = AECreateList(NULL, 0, RTEST(isRecord), &desc);
172
- if (err != noErr) rbAE_raiseMacOSError("Can't create AEDescList.", err);
173
- return rbAE_wrapAEDesc(&desc);
174
- }
175
-
176
-
177
- static VALUE
178
- rbAE_AEDesc_newAppleEvent(VALUE class, VALUE eventClassValue, VALUE eventIDValue,
179
- VALUE targetValue, VALUE returnIDValue, VALUE transactionIDValue)
180
- {
181
- OSErr err = noErr;
182
- AEEventClass theAEEventClass = rbStringToDescType(eventClassValue);
183
- AEEventID theAEEventID = rbStringToDescType(eventIDValue);
184
- AEAddressDesc target = AEDESC_OF(targetValue);
185
- AEReturnID returnID = NUM2INT(returnIDValue);
186
- AETransactionID transactionID = NUM2LONG(transactionIDValue);
187
- AppleEvent result;
188
-
189
- err = AECreateAppleEvent(theAEEventClass,
190
- theAEEventID,
191
- &target,
192
- returnID,
193
- transactionID,
194
- &result);
195
- if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
196
- // workaround for return ID bug in 10.6
197
- AEDesc returnIDDesc;
198
- if (returnID == kAutoGenerateReturnID) {
199
- err = AEGetAttributeDesc(&result, keyReturnIDAttr, typeSInt32, &returnIDDesc);
200
- if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
201
- err = AEGetDescData(&returnIDDesc, &returnID, sizeof(returnID));
202
- if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
203
- if (returnID == -1) {
204
- AEDisposeDesc(&result);
205
- err = AECreateAppleEvent(theAEEventClass,
206
- theAEEventID,
207
- &target,
208
- returnID,
209
- transactionID,
210
- &result);
211
- if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
212
- }
213
- }
214
- return rbAE_wrapAEDesc(&result);
168
+ OSErr err = noErr;
169
+ AEDesc desc;
170
+
171
+ err = AECreateList(NULL, 0, RTEST(isRecord), &desc);
172
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AEDescList.", err);
173
+ return rbAE_wrapAEDesc(&desc);
174
+ }
175
+
176
+
177
+ static VALUE
178
+ rbAE_AEDesc_newAppleEvent(VALUE class, VALUE eventClassValue, VALUE eventIDValue,
179
+ VALUE targetValue, VALUE returnIDValue, VALUE transactionIDValue)
180
+ {
181
+ OSErr err = noErr;
182
+ AEEventClass theAEEventClass = rbStringToDescType(eventClassValue);
183
+ AEEventID theAEEventID = rbStringToDescType(eventIDValue);
184
+ AEAddressDesc target = AEDESC_OF(targetValue);
185
+ AEReturnID returnID = NUM2INT(returnIDValue);
186
+ AETransactionID transactionID = NUM2LONG(transactionIDValue);
187
+ AppleEvent result;
188
+
189
+ err = AECreateAppleEvent(theAEEventClass,
190
+ theAEEventID,
191
+ &target,
192
+ returnID,
193
+ transactionID,
194
+ &result);
195
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
196
+ // workaround for return ID bug in 10.6
197
+ AEDesc returnIDDesc;
198
+ if (returnID == kAutoGenerateReturnID) {
199
+ err = AEGetAttributeDesc(&result, keyReturnIDAttr, typeSInt32, &returnIDDesc);
200
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
201
+ err = AEGetDescData(&returnIDDesc, &returnID, sizeof(returnID));
202
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
203
+ if (returnID == -1) {
204
+ AEDisposeDesc(&result);
205
+ err = AECreateAppleEvent(theAEEventClass,
206
+ theAEEventID,
207
+ &target,
208
+ returnID,
209
+ transactionID,
210
+ &result);
211
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AppleEvent.", err);
212
+ }
213
+ }
214
+ return rbAE_wrapAEDesc(&result);
215
215
  }
216
216
 
217
217
 
218
218
  static VALUE
219
219
  rbAE_AEDesc_newUnflatten(VALUE class, VALUE data)
220
220
  {
221
- OSErr err = noErr;
222
- AEDesc desc;
223
-
224
- Check_Type(data, T_STRING);
225
- err = AEUnflattenDesc(RSTRING_PTR(data), &desc);
226
- if (err != noErr) rbAE_raiseMacOSError("Can't create AEDesc.", err);
227
- return rbAE_wrapAEDesc(&desc);
221
+ OSErr err = noErr;
222
+ AEDesc desc;
223
+
224
+ Check_Type(data, T_STRING);
225
+ err = AEUnflattenDesc(RSTRING_PTR(data), &desc);
226
+ if (err != noErr) rbAE_raiseMacOSError("Can't create AEDesc.", err);
227
+ return rbAE_wrapAEDesc(&desc);
228
228
  }
229
229
 
230
230
 
@@ -234,20 +234,20 @@ rbAE_AEDesc_newUnflatten(VALUE class, VALUE data)
234
234
  static VALUE
235
235
  rbAE_AEDesc_inspect(VALUE self)
236
236
  {
237
- VALUE s, type;
238
- Size dataSize;
239
-
240
- s = rb_str_new2("#<AE::AEDesc type=%s size=%i>");
241
- type = rb_funcall(self, rb_intern("type"), 0);
242
- dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
243
- return rb_funcall(s,
244
- rb_intern("%"),
245
- 1,
246
- rb_ary_new3(2,
247
- rb_funcall(type, rb_intern("inspect"), 0),
248
- INT2NUM(dataSize)
249
- )
250
- );
237
+ VALUE s, type;
238
+ Size dataSize;
239
+
240
+ s = rb_str_new2("#<AE::AEDesc type=%s size=%i>");
241
+ type = rb_funcall(self, rb_intern("type"), 0);
242
+ dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
243
+ return rb_funcall(s,
244
+ rb_intern("%"),
245
+ 1,
246
+ rb_ary_new3(2,
247
+ rb_funcall(type, rb_intern("inspect"), 0),
248
+ INT2NUM(dataSize)
249
+ )
250
+ );
251
251
  }
252
252
 
253
253
 
@@ -255,44 +255,44 @@ rbAE_AEDesc_inspect(VALUE self)
255
255
 
256
256
  static VALUE
257
257
  rbAE_AEDesc_type(VALUE self)
258
- {
259
- return rbDescTypeToString(AEDESC_OF(self).descriptorType);
258
+ {
259
+ return rbDescTypeToString(AEDESC_OF(self).descriptorType);
260
260
  }
261
261
 
262
262
 
263
263
  static VALUE
264
264
  rbAE_AEDesc_data(VALUE self)
265
265
  {
266
- OSErr err = noErr;
267
- Size dataSize;
268
- void *data;
269
- VALUE result;
270
-
271
- dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
272
- data = malloc(dataSize);
273
- err = AEGetDescData(&(AEDESC_OF(self)), data, dataSize);
274
- if (err != noErr) rbAE_raiseMacOSError("Can't get AEDesc data.", err);
275
- result = rb_str_new(data, dataSize);
276
- free(data);
277
- return result;
266
+ OSErr err = noErr;
267
+ Size dataSize;
268
+ void *data;
269
+ VALUE result;
270
+
271
+ dataSize = AEGetDescDataSize(&(AEDESC_OF(self)));
272
+ data = malloc(dataSize);
273
+ err = AEGetDescData(&(AEDESC_OF(self)), data, dataSize);
274
+ if (err != noErr) rbAE_raiseMacOSError("Can't get AEDesc data.", err);
275
+ result = rb_str_new(data, dataSize);
276
+ free(data);
277
+ return result;
278
278
  }
279
279
 
280
280
 
281
281
  static VALUE
282
282
  rbAE_AEDesc_flatten(VALUE self)
283
283
  {
284
- OSErr err = noErr;
285
- Size dataSize;
286
- void *data;
287
- VALUE result;
288
-
289
- dataSize = AESizeOfFlattenedDesc(&(AEDESC_OF(self)));
290
- data = malloc(dataSize);
291
- err = AEFlattenDesc(&(AEDESC_OF(self)), data, dataSize, NULL);
292
- if (err != noErr) rbAE_raiseMacOSError("Can't flatten AEDesc.", err);
293
- result = rb_str_new(data, dataSize);
294
- free(data);
295
- return result;
284
+ OSErr err = noErr;
285
+ Size dataSize;
286
+ void *data;
287
+ VALUE result;
288
+
289
+ dataSize = AESizeOfFlattenedDesc(&(AEDESC_OF(self)));
290
+ data = malloc(dataSize);
291
+ err = AEFlattenDesc(&(AEDESC_OF(self)), data, dataSize, NULL);
292
+ if (err != noErr) rbAE_raiseMacOSError("Can't flatten AEDesc.", err);
293
+ result = rb_str_new(data, dataSize);
294
+ free(data);
295
+ return result;
296
296
  }
297
297
 
298
298
 
@@ -301,31 +301,31 @@ rbAE_AEDesc_flatten(VALUE self)
301
301
  static VALUE
302
302
  rbAE_AEDesc_isRecord(VALUE self)
303
303
  {
304
- return AECheckIsRecord(&(AEDESC_OF(self))) ? Qtrue : Qfalse;
304
+ return AECheckIsRecord(&(AEDESC_OF(self))) ? Qtrue : Qfalse;
305
305
  }
306
306
 
307
307
 
308
308
  static VALUE
309
309
  rbAE_AEDesc_coerce(VALUE self, VALUE type)
310
310
  {
311
- OSErr err = noErr;
312
- AEDesc desc;
313
-
314
- err = AECoerceDesc(&(AEDESC_OF(self)), rbStringToDescType(type), &desc);
315
- if (err != noErr) rbAE_raiseMacOSError("Can't coerce AEDesc.", err);
316
- return rbAE_wrapAEDesc(&desc);
311
+ OSErr err = noErr;
312
+ AEDesc desc;
313
+
314
+ err = AECoerceDesc(&(AEDESC_OF(self)), rbStringToDescType(type), &desc);
315
+ if (err != noErr) rbAE_raiseMacOSError("Can't coerce AEDesc.", err);
316
+ return rbAE_wrapAEDesc(&desc);
317
317
  }
318
318
 
319
319
 
320
320
  static VALUE
321
321
  rbAE_AEDesc_length(VALUE self)
322
322
  {
323
- OSErr err = noErr;
324
- long length;
325
-
326
- err = AECountItems(&(AEDESC_OF(self)), &length);
327
- if (err != noErr) rbAE_raiseMacOSError("Can't get length of AEDesc.", err);
328
- return INT2NUM(length);
323
+ OSErr err = noErr;
324
+ long length;
325
+
326
+ err = AECountItems(&(AEDESC_OF(self)), &length);
327
+ if (err != noErr) rbAE_raiseMacOSError("Can't get length of AEDesc.", err);
328
+ return INT2NUM(length);
329
329
  }
330
330
 
331
331
 
@@ -334,39 +334,39 @@ rbAE_AEDesc_length(VALUE self)
334
334
  static VALUE
335
335
  rbAE_AEDesc_putItem(VALUE self, VALUE index, VALUE desc)
336
336
  {
337
- OSErr err = noErr;
338
-
339
- if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
340
- rb_raise(rb_eTypeError, "Can't put non-AEDesc item into AEDesc.");
341
- err = AEPutDesc(&(AEDESC_OF(self)), NUM2LONG(index), &(AEDESC_OF(desc)));
342
- if (err != noErr) rbAE_raiseMacOSError("Can't put item into AEDesc.", err);
343
- return Qnil;
337
+ OSErr err = noErr;
338
+
339
+ if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
340
+ rb_raise(rb_eTypeError, "Can't put non-AEDesc item into AEDesc.");
341
+ err = AEPutDesc(&(AEDESC_OF(self)), NUM2LONG(index), &(AEDESC_OF(desc)));
342
+ if (err != noErr) rbAE_raiseMacOSError("Can't put item into AEDesc.", err);
343
+ return Qnil;
344
344
  }
345
345
 
346
346
 
347
347
  static VALUE
348
348
  rbAE_AEDesc_putParam(VALUE self, VALUE key, VALUE desc)
349
349
  {
350
- OSErr err = noErr;
351
-
352
- if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
353
- rb_raise(rb_eTypeError, "Can't put non-AEDesc parameter into AEDesc.");
354
- err = AEPutParamDesc(&(AEDESC_OF(self)), rbStringToDescType(key), &(AEDESC_OF(desc)));
355
- if (err != noErr) rbAE_raiseMacOSError("Can't put parameter into AEDesc.", err);
356
- return Qnil;
350
+ OSErr err = noErr;
351
+
352
+ if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
353
+ rb_raise(rb_eTypeError, "Can't put non-AEDesc parameter into AEDesc.");
354
+ err = AEPutParamDesc(&(AEDESC_OF(self)), rbStringToDescType(key), &(AEDESC_OF(desc)));
355
+ if (err != noErr) rbAE_raiseMacOSError("Can't put parameter into AEDesc.", err);
356
+ return Qnil;
357
357
  }
358
358
 
359
359
 
360
360
  static VALUE
361
361
  rbAE_AEDesc_putAttr(VALUE self, VALUE key, VALUE desc)
362
362
  {
363
- OSErr err = noErr;
364
-
365
- if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
366
- rb_raise(rb_eTypeError, "Can't put non-AEDesc attribute into AEDesc.");
367
- err = AEPutAttributeDesc(&(AEDESC_OF(self)), rbStringToDescType(key), &(AEDESC_OF(desc)));
368
- if (err != noErr) rbAE_raiseMacOSError("Can't put attribute into AEDesc.", err);
369
- return Qnil;
363
+ OSErr err = noErr;
364
+
365
+ if (rb_obj_is_instance_of(desc, cAEDesc) == Qfalse)
366
+ rb_raise(rb_eTypeError, "Can't put non-AEDesc attribute into AEDesc.");
367
+ err = AEPutAttributeDesc(&(AEDESC_OF(self)), rbStringToDescType(key), &(AEDESC_OF(desc)));
368
+ if (err != noErr) rbAE_raiseMacOSError("Can't put attribute into AEDesc.", err);
369
+ return Qnil;
370
370
  }
371
371
 
372
372
 
@@ -375,49 +375,49 @@ rbAE_AEDesc_putAttr(VALUE self, VALUE key, VALUE desc)
375
375
  static VALUE
376
376
  rbAE_AEDesc_getItem(VALUE self, VALUE index, VALUE type)
377
377
  {
378
- OSErr err = noErr;
379
- AEKeyword key;
380
- AEDesc desc;
381
-
382
- err = AEGetNthDesc(&(AEDESC_OF(self)),
383
- NUM2LONG(index),
384
- rbStringToDescType(type),
385
- &key,
386
- &desc);
387
- if (err != noErr) rbAE_raiseMacOSError("Can't get item from AEDesc.", err);
388
- return rb_ary_new3(2,
389
- rbDescTypeToString(key),
390
- rbAE_wrapAEDesc(&desc));
378
+ OSErr err = noErr;
379
+ AEKeyword key;
380
+ AEDesc desc;
381
+
382
+ err = AEGetNthDesc(&(AEDESC_OF(self)),
383
+ NUM2LONG(index),
384
+ rbStringToDescType(type),
385
+ &key,
386
+ &desc);
387
+ if (err != noErr) rbAE_raiseMacOSError("Can't get item from AEDesc.", err);
388
+ return rb_ary_new3(2,
389
+ rbDescTypeToString(key),
390
+ rbAE_wrapAEDesc(&desc));
391
391
  }
392
392
 
393
393
 
394
394
  static VALUE
395
395
  rbAE_AEDesc_getParam(VALUE self, VALUE key, VALUE type)
396
396
  {
397
- OSErr err = noErr;
398
- AEDesc desc;
399
-
400
- err = AEGetParamDesc(&(AEDESC_OF(self)),
401
- rbStringToDescType(key),
402
- rbStringToDescType(type),
403
- &desc);
404
- if (err != noErr) rbAE_raiseMacOSError("Can't get parameter from AEDesc.", err);
405
- return rbAE_wrapAEDesc(&desc);
397
+ OSErr err = noErr;
398
+ AEDesc desc;
399
+
400
+ err = AEGetParamDesc(&(AEDESC_OF(self)),
401
+ rbStringToDescType(key),
402
+ rbStringToDescType(type),
403
+ &desc);
404
+ if (err != noErr) rbAE_raiseMacOSError("Can't get parameter from AEDesc.", err);
405
+ return rbAE_wrapAEDesc(&desc);
406
406
  }
407
407
 
408
408
 
409
409
  static VALUE
410
410
  rbAE_AEDesc_getAttr(VALUE self, VALUE key, VALUE type)
411
411
  {
412
- OSErr err = noErr;
413
- AEDesc desc;
414
-
415
- err = AEGetAttributeDesc(&(AEDESC_OF(self)),
416
- rbStringToDescType(key),
417
- rbStringToDescType(type),
418
- &desc);
419
- if (err != noErr) rbAE_raiseMacOSError("Can't get attribute from AEDesc.", err);
420
- return rbAE_wrapAEDesc(&desc);
412
+ OSErr err = noErr;
413
+ AEDesc desc;
414
+
415
+ err = AEGetAttributeDesc(&(AEDESC_OF(self)),
416
+ rbStringToDescType(key),
417
+ rbStringToDescType(type),
418
+ &desc);
419
+ if (err != noErr) rbAE_raiseMacOSError("Can't get attribute from AEDesc.", err);
420
+ return rbAE_wrapAEDesc(&desc);
421
421
  }
422
422
 
423
423
 
@@ -426,29 +426,29 @@ rbAE_AEDesc_getAttr(VALUE self, VALUE key, VALUE type)
426
426
  static VALUE
427
427
  rbAE_AEDesc_send(VALUE self, VALUE sendMode, VALUE timeout)
428
428
  {
429
- OSErr err = noErr;
430
- AppleEvent reply;
431
-
432
- err = AESendMessage(&(AEDESC_OF(self)),
433
- &reply,
434
- (AESendMode)NUM2LONG(sendMode),
435
- NUM2LONG(timeout));
436
- if (err != noErr) rbAE_raiseMacOSError("Can't send Apple event.", err);
437
- return rbAE_wrapAEDesc(&reply);
429
+ OSErr err = noErr;
430
+ AppleEvent reply;
431
+
432
+ err = AESendMessage(&(AEDESC_OF(self)),
433
+ &reply,
434
+ (AESendMode)NUM2LONG(sendMode),
435
+ NUM2LONG(timeout));
436
+ if (err != noErr) rbAE_raiseMacOSError("Can't send Apple event.", err);
437
+ return rbAE_wrapAEDesc(&reply);
438
438
  }
439
439
 
440
440
  static VALUE
441
441
  rbAE_AEDesc_sendThreadSafe(VALUE self, VALUE sendMode, VALUE timeout)
442
442
  {
443
- OSErr err = noErr;
444
- AppleEvent reply;
445
-
446
- err = SendMessageThreadSafe(&(AEDESC_OF(self)),
447
- &reply,
448
- (AESendMode)NUM2LONG(sendMode),
449
- NUM2LONG(timeout));
450
- if (err != noErr) rbAE_raiseMacOSError("Can't send Apple event.", err);
451
- return rbAE_wrapAEDesc(&reply);
443
+ OSErr err = noErr;
444
+ AppleEvent reply;
445
+
446
+ err = SendMessageThreadSafe(&(AEDESC_OF(self)),
447
+ &reply,
448
+ (AESendMode)NUM2LONG(sendMode),
449
+ NUM2LONG(timeout));
450
+ if (err != noErr) rbAE_raiseMacOSError("Can't send Apple event.", err);
451
+ return rbAE_wrapAEDesc(&reply);
452
452
  }
453
453
 
454
454
 
@@ -458,101 +458,101 @@ rbAE_AEDesc_sendThreadSafe(VALUE self, VALUE sendMode, VALUE timeout)
458
458
  static VALUE
459
459
  rbAE_findApplication(VALUE self, VALUE creator, VALUE bundleID, VALUE name)
460
460
  {
461
- OSStatus err = 0;
462
-
463
- OSType inCreator;
464
- CFStringRef inName;
465
- CFStringRef inBundleID;
466
- FSRef outAppRef;
467
- UInt8 path[PATH_MAX];
468
-
469
- inCreator = (creator == Qnil) ? kLSUnknownCreator : rbStringToDescType(creator);
470
- if (bundleID != Qnil) {
471
- inBundleID = CFStringCreateWithBytes(NULL,
472
- (UInt8 *)(RSTRING_PTR(bundleID)),
473
- (CFIndex)(RSTRING_LEN(bundleID)),
474
- kCFStringEncodingUTF8,
475
- false);
476
- if (inBundleID == NULL) rb_raise(rb_eRuntimeError, "Invalid bundle ID string.");
477
- } else {
478
- inBundleID = NULL;
479
- }
480
- if (name != Qnil) {
481
- inName = CFStringCreateWithBytes(NULL,
482
- (UInt8 *)(RSTRING_PTR(name)),
483
- (CFIndex)(RSTRING_LEN(name)),
484
- kCFStringEncodingUTF8,
485
- false);
486
- if (inName == NULL) {
487
- if (inBundleID != NULL) CFRelease(inBundleID);
488
- rb_raise(rb_eRuntimeError, "Invalid name string.");
489
- }
490
- } else {
491
- inName = NULL;
492
- }
493
- err = LSFindApplicationForInfo(inCreator,
494
- inBundleID,
495
- inName,
496
- &outAppRef,
497
- NULL);
498
- if (inBundleID != NULL) CFRelease(inBundleID);
499
- if (inName != NULL) CFRelease(inName);
500
- if (err != 0) rbAE_raiseMacOSError("Couldn't find application.", err);
501
- err = FSRefMakePath(&outAppRef, path, PATH_MAX);
502
- if (err != 0) rbAE_raiseMacOSError("Couldn't get application path.", err);
503
- return rb_str_new2((char *)path);
461
+ OSStatus err = 0;
462
+
463
+ OSType inCreator;
464
+ CFStringRef inName;
465
+ CFStringRef inBundleID;
466
+ FSRef outAppRef;
467
+ UInt8 path[PATH_MAX];
468
+
469
+ inCreator = (creator == Qnil) ? kLSUnknownCreator : rbStringToDescType(creator);
470
+ if (bundleID != Qnil) {
471
+ inBundleID = CFStringCreateWithBytes(NULL,
472
+ (UInt8 *)(RSTRING_PTR(bundleID)),
473
+ (CFIndex)(RSTRING_LEN(bundleID)),
474
+ kCFStringEncodingUTF8,
475
+ false);
476
+ if (inBundleID == NULL) rb_raise(rb_eRuntimeError, "Invalid bundle ID string.");
477
+ } else {
478
+ inBundleID = NULL;
479
+ }
480
+ if (name != Qnil) {
481
+ inName = CFStringCreateWithBytes(NULL,
482
+ (UInt8 *)(RSTRING_PTR(name)),
483
+ (CFIndex)(RSTRING_LEN(name)),
484
+ kCFStringEncodingUTF8,
485
+ false);
486
+ if (inName == NULL) {
487
+ if (inBundleID != NULL) CFRelease(inBundleID);
488
+ rb_raise(rb_eRuntimeError, "Invalid name string.");
489
+ }
490
+ } else {
491
+ inName = NULL;
492
+ }
493
+ err = LSFindApplicationForInfo(inCreator,
494
+ inBundleID,
495
+ inName,
496
+ &outAppRef,
497
+ NULL);
498
+ if (inBundleID != NULL) CFRelease(inBundleID);
499
+ if (inName != NULL) CFRelease(inName);
500
+ if (err != 0) rbAE_raiseMacOSError("Couldn't find application.", err);
501
+ err = FSRefMakePath(&outAppRef, path, PATH_MAX);
502
+ if (err != 0) rbAE_raiseMacOSError("Couldn't get application path.", err);
503
+ return rb_str_new2((char *)path);
504
504
  }
505
505
 
506
506
 
507
507
  static VALUE
508
508
  rbAE_psnForApplicationPath(VALUE self, VALUE path)
509
509
  {
510
- OSStatus err = noErr;
511
- ProcessSerialNumber psn = {0, kNoProcess};
512
- FSRef appRef, foundRef;
510
+ OSStatus err = noErr;
511
+ ProcessSerialNumber psn = {0, kNoProcess};
512
+ FSRef appRef, foundRef;
513
513
 
514
- err = FSPathMakeRef((UInt8 *)StringValuePtr(path), &appRef, NULL);
515
- if (err != 0) rbAE_raiseMacOSError("Couldn't make FSRef for application.", err);
516
- while (1) {
517
- err = GetNextProcess(&psn);
518
- if (err != 0) rbAE_raiseMacOSError("Can't get next process.", err); // -600 if no more processes left
519
- err = GetProcessBundleLocation(&psn, &foundRef);
520
- if (err != 0) continue;
521
- if (FSCompareFSRefs(&appRef, &foundRef) == noErr)
522
- return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
523
- }
514
+ err = FSPathMakeRef((UInt8 *)StringValuePtr(path), &appRef, NULL);
515
+ if (err != 0) rbAE_raiseMacOSError("Couldn't make FSRef for application.", err);
516
+ while (1) {
517
+ err = GetNextProcess(&psn);
518
+ if (err != 0) rbAE_raiseMacOSError("Can't get next process.", err); // -600 if no more processes left
519
+ err = GetProcessBundleLocation(&psn, &foundRef);
520
+ if (err != 0) continue;
521
+ if (FSCompareFSRefs(&appRef, &foundRef) == noErr)
522
+ return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
523
+ }
524
524
  }
525
525
 
526
526
 
527
527
  static VALUE
528
528
  rbAE_psnForPID(VALUE self, VALUE pid)
529
529
  {
530
- OSStatus err = noErr;
531
- ProcessSerialNumber psn = {0, kNoProcess};
530
+ OSStatus err = noErr;
531
+ ProcessSerialNumber psn = {0, kNoProcess};
532
532
 
533
- err = GetProcessForPID(NUM2INT(pid), &psn);
534
- if (err != 0) rbAE_raiseMacOSError("Can't get next process.", err); // -600 if process not found
535
- return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
533
+ err = GetProcessForPID(NUM2INT(pid), &psn);
534
+ if (err != 0) rbAE_raiseMacOSError("Can't get next process.", err); // -600 if process not found
535
+ return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
536
536
  }
537
537
 
538
538
 
539
539
  static VALUE
540
540
  rbAE_launchApplication(VALUE self, VALUE path, VALUE firstEvent, VALUE flags)
541
541
  {
542
- FSRef appRef;
543
- ProcessSerialNumber psn;
544
- OSStatus err = noErr;
545
-
546
- err = FSPathMakeRef((UInt8 *)StringValuePtr(path), &appRef, NULL);
547
- if (err != noErr) rbAE_raiseMacOSError("Couldn't make FSRef for application.", err);
548
- LSApplicationParameters appParams = {0,
549
- (LSLaunchFlags)NUM2UINT(flags),
550
- &appRef,
551
- NULL, NULL, NULL,
552
- &(AEDESC_OF(firstEvent))};
553
- err = LSOpenApplication(&appParams, &psn);
554
- if (err != noErr) rbAE_raiseMacOSError("Can't launch application.", err);
555
- return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
542
+ FSRef appRef;
543
+ ProcessSerialNumber psn;
544
+ OSStatus err = noErr;
545
+
546
+ err = FSPathMakeRef((UInt8 *)StringValuePtr(path), &appRef, NULL);
547
+ if (err != noErr) rbAE_raiseMacOSError("Couldn't make FSRef for application.", err);
548
+ LSApplicationParameters appParams = {0,
549
+ (LSLaunchFlags)NUM2UINT(flags),
550
+ &appRef,
551
+ NULL, NULL, NULL,
552
+ &(AEDESC_OF(firstEvent))};
553
+ err = LSOpenApplication(&appParams, &psn);
554
+ if (err != noErr) rbAE_raiseMacOSError("Can't launch application.", err);
555
+ return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
556
556
  }
557
557
 
558
558
  /**********************************************************************/
@@ -561,51 +561,51 @@ rbAE_launchApplication(VALUE self, VALUE path, VALUE firstEvent, VALUE flags)
561
561
  static VALUE
562
562
  rbAE_convertPathToURL(VALUE self, VALUE path, VALUE pathStyle)
563
563
  {
564
- CFStringRef str;
565
- CFURLRef url;
566
- UInt8 buffer[PATH_MAX];
567
-
568
- str = CFStringCreateWithBytes(NULL,
569
- (UInt8 *)(RSTRING_PTR(path)),
570
- (CFIndex)(RSTRING_LEN(path)),
571
- kCFStringEncodingUTF8,
572
- false);
573
- if (str == NULL) rb_raise(rb_eRuntimeError, "Bad path string.");
574
- url = CFURLCreateWithFileSystemPath(NULL,
575
- str,
576
- NUM2LONG(pathStyle),
577
- false);
578
- CFRelease(str);
579
- if (url == NULL) rb_raise(rb_eRuntimeError, "Invalid path.");
580
- buffer[CFURLGetBytes(url, buffer, PATH_MAX - 1)] = '\0';
581
- CFRelease(url);
582
- return rb_str_new2((char *)buffer);
564
+ CFStringRef str;
565
+ CFURLRef url;
566
+ UInt8 buffer[PATH_MAX];
567
+
568
+ str = CFStringCreateWithBytes(NULL,
569
+ (UInt8 *)(RSTRING_PTR(path)),
570
+ (CFIndex)(RSTRING_LEN(path)),
571
+ kCFStringEncodingUTF8,
572
+ false);
573
+ if (str == NULL) rb_raise(rb_eRuntimeError, "Bad path string.");
574
+ url = CFURLCreateWithFileSystemPath(NULL,
575
+ str,
576
+ NUM2LONG(pathStyle),
577
+ false);
578
+ CFRelease(str);
579
+ if (url == NULL) rb_raise(rb_eRuntimeError, "Invalid path.");
580
+ buffer[CFURLGetBytes(url, buffer, PATH_MAX - 1)] = '\0';
581
+ CFRelease(url);
582
+ return rb_str_new2((char *)buffer);
583
583
  }
584
584
 
585
585
  static VALUE
586
586
  rbAE_convertURLToPath(VALUE self, VALUE urlStr, VALUE pathStyle)
587
587
  {
588
- Boolean err;
589
- CFURLRef url;
590
- CFStringRef str;
591
- char buffer[PATH_MAX];
592
-
593
- url = CFURLCreateWithBytes(NULL,
594
- (UInt8 *)(RSTRING_PTR(urlStr)),
595
- (CFIndex)(RSTRING_LEN(urlStr)),
596
- kCFStringEncodingUTF8,
597
- NULL);
598
- if (url == NULL) rb_raise(rb_eRuntimeError, "Bad URL string.");
599
- str = CFURLCopyFileSystemPath(url, NUM2LONG(pathStyle));
600
- CFRelease(url);
601
- if (str == NULL) rb_raise(rb_eRuntimeError, "Can't get path.");
602
- err = CFStringGetCString(str,
603
- buffer,
604
- PATH_MAX,
605
- kCFStringEncodingUTF8);
606
- CFRelease(str);
607
- if (!err) rb_raise(rb_eRuntimeError, "Can't get path.");
608
- return rb_str_new2(buffer);
588
+ Boolean err;
589
+ CFURLRef url;
590
+ CFStringRef str;
591
+ char buffer[PATH_MAX];
592
+
593
+ url = CFURLCreateWithBytes(NULL,
594
+ (UInt8 *)(RSTRING_PTR(urlStr)),
595
+ (CFIndex)(RSTRING_LEN(urlStr)),
596
+ kCFStringEncodingUTF8,
597
+ NULL);
598
+ if (url == NULL) rb_raise(rb_eRuntimeError, "Bad URL string.");
599
+ str = CFURLCopyFileSystemPath(url, NUM2LONG(pathStyle));
600
+ CFRelease(url);
601
+ if (str == NULL) rb_raise(rb_eRuntimeError, "Can't get path.");
602
+ err = CFStringGetCString(str,
603
+ buffer,
604
+ PATH_MAX,
605
+ kCFStringEncodingUTF8);
606
+ CFRelease(str);
607
+ if (!err) rb_raise(rb_eRuntimeError, "Can't get path.");
608
+ return rb_str_new2(buffer);
609
609
  }
610
610
 
611
611
 
@@ -615,81 +615,81 @@ rbAE_convertURLToPath(VALUE self, VALUE urlStr, VALUE pathStyle)
615
615
  static VALUE
616
616
  rbAE_convertLongDateTimeToString(VALUE self, VALUE ldt)
617
617
  {
618
- Boolean bErr;
619
- OSStatus err = 0;
620
- CFAbsoluteTime cfTime;
621
- CFDateFormatterRef formatter;
622
- CFStringRef str;
623
- char buffer[20]; // size of format string + nul
624
-
625
- err = UCConvertLongDateTimeToCFAbsoluteTime(NUM2LL(ldt), &cfTime);
626
- if (err != noErr) rbAE_raiseMacOSError("Can't convert LongDateTime to seconds.", err);
627
- formatter = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
628
- if (!formatter) rbAE_raiseMacOSError("Can't create date formatter.", err);
629
- CFDateFormatterSetFormat(formatter, CFSTR("yyyy-MM-dd HH:mm:ss"));
630
- str = CFDateFormatterCreateStringWithAbsoluteTime(NULL, formatter, cfTime);
631
- CFRelease(formatter);
632
- if (!str) rbAE_raiseMacOSError("Can't create date string.", err);
633
- bErr = CFStringGetCString(str,
634
- buffer,
635
- sizeof(buffer),
636
- kCFStringEncodingUTF8);
637
- CFRelease(str);
638
- if (!bErr) rb_raise(rb_eRuntimeError, "Can't convert date string.");
639
- return rb_str_new2(buffer);
618
+ Boolean bErr;
619
+ OSStatus err = 0;
620
+ CFAbsoluteTime cfTime;
621
+ CFDateFormatterRef formatter;
622
+ CFStringRef str;
623
+ char buffer[20]; // size of format string + nul
624
+
625
+ err = UCConvertLongDateTimeToCFAbsoluteTime(NUM2LL(ldt), &cfTime);
626
+ if (err != noErr) rbAE_raiseMacOSError("Can't convert LongDateTime to seconds.", err);
627
+ formatter = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
628
+ if (!formatter) rbAE_raiseMacOSError("Can't create date formatter.", err);
629
+ CFDateFormatterSetFormat(formatter, CFSTR("yyyy-MM-dd HH:mm:ss"));
630
+ str = CFDateFormatterCreateStringWithAbsoluteTime(NULL, formatter, cfTime);
631
+ CFRelease(formatter);
632
+ if (!str) rbAE_raiseMacOSError("Can't create date string.", err);
633
+ bErr = CFStringGetCString(str,
634
+ buffer,
635
+ sizeof(buffer),
636
+ kCFStringEncodingUTF8);
637
+ CFRelease(str);
638
+ if (!bErr) rb_raise(rb_eRuntimeError, "Can't convert date string.");
639
+ return rb_str_new2(buffer);
640
640
  }
641
641
 
642
642
 
643
643
  static VALUE
644
644
  rbAE_convertStringToLongDateTime(VALUE self, VALUE datetime)
645
645
  {
646
- CFStringRef str;
647
- CFAbsoluteTime cfTime;
648
- CFDateFormatterRef formatter;
649
- OSStatus err = 0;
650
- Boolean bErr;
651
- SInt64 ldt;
652
-
653
- str = CFStringCreateWithBytes(NULL,
654
- (UInt8 *)(RSTRING_PTR(datetime)),
655
- (CFIndex)(RSTRING_LEN(datetime)),
656
- kCFStringEncodingUTF8,
657
- false);
658
- if (str == NULL || CFStringGetLength(str) != 19) rb_raise(rb_eRuntimeError, "Bad datetime string.");
659
- formatter = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
660
- if (!formatter) rbAE_raiseMacOSError("Can't create date formatter.", err);
661
- CFDateFormatterSetFormat(formatter, CFSTR("yyyy-MM-dd HH:mm:ss"));
662
- bErr = CFDateFormatterGetAbsoluteTimeFromString(formatter, str, NULL, &cfTime);
663
- CFRelease(formatter);
664
- CFRelease(str);
665
- if (!bErr) rb_raise(rb_eRuntimeError, "Can't convert date string.");
666
- err = UCConvertCFAbsoluteTimeToLongDateTime(cfTime, &ldt);
667
- if (err != noErr) rbAE_raiseMacOSError("Can't convert seconds to LongDateTime.", err);
668
- return LL2NUM(ldt);
646
+ CFStringRef str;
647
+ CFAbsoluteTime cfTime;
648
+ CFDateFormatterRef formatter;
649
+ OSStatus err = 0;
650
+ Boolean bErr;
651
+ SInt64 ldt;
652
+
653
+ str = CFStringCreateWithBytes(NULL,
654
+ (UInt8 *)(RSTRING_PTR(datetime)),
655
+ (CFIndex)(RSTRING_LEN(datetime)),
656
+ kCFStringEncodingUTF8,
657
+ false);
658
+ if (str == NULL || CFStringGetLength(str) != 19) rb_raise(rb_eRuntimeError, "Bad datetime string.");
659
+ formatter = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle);
660
+ if (!formatter) rbAE_raiseMacOSError("Can't create date formatter.", err);
661
+ CFDateFormatterSetFormat(formatter, CFSTR("yyyy-MM-dd HH:mm:ss"));
662
+ bErr = CFDateFormatterGetAbsoluteTimeFromString(formatter, str, NULL, &cfTime);
663
+ CFRelease(formatter);
664
+ CFRelease(str);
665
+ if (!bErr) rb_raise(rb_eRuntimeError, "Can't convert date string.");
666
+ err = UCConvertCFAbsoluteTimeToLongDateTime(cfTime, &ldt);
667
+ if (err != noErr) rbAE_raiseMacOSError("Can't convert seconds to LongDateTime.", err);
668
+ return LL2NUM(ldt);
669
669
  }
670
670
 
671
671
 
672
672
  static VALUE
673
673
  rbAE_convertLongDateTimeToUnixSeconds(VALUE self, VALUE ldt)
674
674
  {
675
- OSStatus err = 0;
676
- CFAbsoluteTime cfTime;
677
-
678
- err = UCConvertLongDateTimeToCFAbsoluteTime(NUM2LL(ldt), &cfTime);
679
- if (err != noErr) rbAE_raiseMacOSError("Can't convert LongDateTime to seconds.", err);
680
- return rb_float_new(cfTime + kCFAbsoluteTimeIntervalSince1970);
675
+ OSStatus err = 0;
676
+ CFAbsoluteTime cfTime;
677
+
678
+ err = UCConvertLongDateTimeToCFAbsoluteTime(NUM2LL(ldt), &cfTime);
679
+ if (err != noErr) rbAE_raiseMacOSError("Can't convert LongDateTime to seconds.", err);
680
+ return rb_float_new(cfTime + kCFAbsoluteTimeIntervalSince1970);
681
681
  }
682
682
 
683
683
 
684
684
  static VALUE
685
685
  rbAE_convertUnixSecondsToLongDateTime(VALUE self, VALUE secs)
686
686
  {
687
- OSStatus err = 0;
688
- SInt64 ldt;
687
+ OSStatus err = 0;
688
+ SInt64 ldt;
689
689
 
690
- err = UCConvertCFAbsoluteTimeToLongDateTime(NUM2DBL(secs) - kCFAbsoluteTimeIntervalSince1970, &ldt);
691
- if (err != noErr) rbAE_raiseMacOSError("Can't convert seconds to LongDateTime.", err);
692
- return LL2NUM(ldt);
690
+ err = UCConvertCFAbsoluteTimeToLongDateTime(NUM2DBL(secs) - kCFAbsoluteTimeIntervalSince1970, &ldt);
691
+ if (err != noErr) rbAE_raiseMacOSError("Can't convert seconds to LongDateTime.", err);
692
+ return LL2NUM(ldt);
693
693
  }
694
694
 
695
695
 
@@ -699,29 +699,29 @@ rbAE_convertUnixSecondsToLongDateTime(VALUE self, VALUE secs)
699
699
  static VALUE
700
700
  rbAE_OSACopyScriptingDefinition(VALUE self, VALUE path)
701
701
  {
702
- FSRef fsRef;
703
- CFDataRef sdef;
704
- CFIndex dataSize;
705
- char *data;
706
- VALUE res;
707
- OSErr err = noErr;
708
-
709
- err = FSPathMakeRef((UInt8 *)StringValuePtr(path), &fsRef, NULL);
710
- if (err != 0) rbAE_raiseMacOSError("Couldn't make FSRef for path.", err);
711
- err = OSACopyScriptingDefinition(&fsRef, 0, &sdef);
712
- if (err) rbAE_raiseMacOSError("Couldn't get sdef.", err);
713
- dataSize = CFDataGetLength(sdef);
714
- data = (char *)CFDataGetBytePtr(sdef);
715
- if (data != NULL) {
716
- res = rb_str_new(data, dataSize);
717
- } else {
718
- data = malloc(dataSize);
719
- CFDataGetBytes(sdef, CFRangeMake(0, dataSize), (UInt8 *)data);
720
- res = rb_str_new(data, dataSize);
721
- free(data);
722
- }
723
- CFRelease(sdef);
724
- return res;
702
+ FSRef fsRef;
703
+ CFDataRef sdef;
704
+ CFIndex dataSize;
705
+ char *data;
706
+ VALUE res;
707
+ OSErr err = noErr;
708
+
709
+ err = FSPathMakeRef((UInt8 *)StringValuePtr(path), &fsRef, NULL);
710
+ if (err != 0) rbAE_raiseMacOSError("Couldn't make FSRef for path.", err);
711
+ err = OSACopyScriptingDefinition(&fsRef, 0, &sdef);
712
+ if (err) rbAE_raiseMacOSError("Couldn't get sdef.", err);
713
+ dataSize = CFDataGetLength(sdef);
714
+ data = (char *)CFDataGetBytePtr(sdef);
715
+ if (data != NULL) {
716
+ res = rb_str_new(data, dataSize);
717
+ } else {
718
+ data = malloc(dataSize);
719
+ CFDataGetBytes(sdef, CFRangeMake(0, dataSize), (UInt8 *)data);
720
+ res = rb_str_new(data, dataSize);
721
+ free(data);
722
+ }
723
+ CFRelease(sdef);
724
+ return res;
725
725
  }
726
726
 
727
727
 
@@ -733,14 +733,14 @@ rbAE_OSACopyScriptingDefinition(VALUE self, VALUE path)
733
733
  static pascal OSErr
734
734
  rbAE_GenericEventHandler(const AppleEvent *request, AppleEvent *reply, SRefCon refcon)
735
735
  {
736
- VALUE err;
737
-
738
- err = rb_funcall((VALUE)refcon,
739
- rb_intern("handle_event"),
740
- 2,
741
- rbAE_wrapBorrowedAEDesc(request),
742
- rbAE_wrapBorrowedAEDesc(reply));
743
- return NUM2INT(err);
736
+ VALUE err;
737
+
738
+ err = rb_funcall((VALUE)refcon,
739
+ rb_intern("handle_event"),
740
+ 2,
741
+ rbAE_wrapBorrowedAEDesc(request),
742
+ rbAE_wrapBorrowedAEDesc(reply));
743
+ return NUM2INT(err);
744
744
  }
745
745
 
746
746
  /*******/
@@ -748,52 +748,52 @@ rbAE_GenericEventHandler(const AppleEvent *request, AppleEvent *reply, SRefCon r
748
748
  static VALUE
749
749
  rbAE_AEInstallEventHandler(VALUE self, VALUE eventClass, VALUE eventID, SRefCon handler)
750
750
  {
751
- /*
752
- * eventClass and eventID must be four-character code strings
753
- *
754
- * handler must be a Ruby object containing a method named 'handle_event' that takes two
755
- * AppleEvent descriptors (request and reply) as arguments, and returns an integer.
756
- * Note that this object is responsible for trapping any unhandled exceptions and returning
757
- * an OS error number as appropriate (or 0 if no error), otherwise the program will exit.
758
- */
759
- OSErr err = noErr;
760
-
761
- err = AEInstallEventHandler(rbStringToDescType(eventClass),
762
- rbStringToDescType(eventID),
763
- upp_GenericEventHandler, handler,
764
- 0);
765
- if (err != noErr) rbAE_raiseMacOSError("Can't install event handler.", err);
766
- return Qnil;
751
+ /*
752
+ * eventClass and eventID must be four-character code strings
753
+ *
754
+ * handler must be a Ruby object containing a method named 'handle_event' that takes two
755
+ * AppleEvent descriptors (request and reply) as arguments, and returns an integer.
756
+ * Note that this object is responsible for trapping any unhandled exceptions and returning
757
+ * an OS error number as appropriate (or 0 if no error), otherwise the program will exit.
758
+ */
759
+ OSErr err = noErr;
760
+
761
+ err = AEInstallEventHandler(rbStringToDescType(eventClass),
762
+ rbStringToDescType(eventID),
763
+ upp_GenericEventHandler, handler,
764
+ 0);
765
+ if (err != noErr) rbAE_raiseMacOSError("Can't install event handler.", err);
766
+ return Qnil;
767
767
  }
768
768
 
769
769
 
770
770
  static VALUE
771
771
  rbAE_AERemoveEventHandler(VALUE self, VALUE eventClass, VALUE eventID)
772
772
  {
773
- OSErr err = noErr;
774
-
775
- err = AERemoveEventHandler(rbStringToDescType(eventClass),
776
- rbStringToDescType(eventID),
777
- upp_GenericEventHandler,
778
- 0);
779
- if (err != noErr) rbAE_raiseMacOSError("Can't remove event handler.", err);
780
- return Qnil;
773
+ OSErr err = noErr;
774
+
775
+ err = AERemoveEventHandler(rbStringToDescType(eventClass),
776
+ rbStringToDescType(eventID),
777
+ upp_GenericEventHandler,
778
+ 0);
779
+ if (err != noErr) rbAE_raiseMacOSError("Can't remove event handler.", err);
780
+ return Qnil;
781
781
  }
782
782
 
783
783
 
784
784
  static VALUE
785
785
  rbAE_AEGetEventHandler(VALUE self, VALUE eventClass, VALUE eventID)
786
786
  {
787
- OSErr err = noErr;
788
- AEEventHandlerUPP handlerUPP;
789
- SRefCon handler;
790
-
791
- err = AEGetEventHandler(rbStringToDescType(eventClass),
792
- rbStringToDescType(eventID),
793
- &handlerUPP, &handler,
794
- 0);
795
- if (err != noErr) rbAE_raiseMacOSError("Can't get event handler.", err);
796
- return (VALUE)handler;
787
+ OSErr err = noErr;
788
+ AEEventHandlerUPP handlerUPP;
789
+ SRefCon handler;
790
+
791
+ err = AEGetEventHandler(rbStringToDescType(eventClass),
792
+ rbStringToDescType(eventID),
793
+ &handlerUPP, &handler,
794
+ 0);
795
+ if (err != noErr) rbAE_raiseMacOSError("Can't get event handler.", err);
796
+ return (VALUE)handler;
797
797
  }
798
798
 
799
799
 
@@ -803,18 +803,18 @@ rbAE_AEGetEventHandler(VALUE self, VALUE eventClass, VALUE eventID)
803
803
  static pascal OSErr
804
804
  rbAE_GenericCoercionHandler(const AEDesc *fromDesc, DescType toType, SRefCon refcon, AEDesc *toDesc)
805
805
  {
806
- // handle_coercion method should return an AE::AEDesc, or nil if an error occurred
807
- OSErr err = noErr;
808
- VALUE res;
809
-
810
- res = rb_funcall((VALUE)refcon,
811
- rb_intern("handle_coercion"),
812
- 2,
813
- rbAE_wrapBorrowedAEDesc(fromDesc),
814
- rbDescTypeToString(toType));
815
- if (rb_obj_is_instance_of(res, cAEDesc) != Qtrue) return errAECoercionFail;
816
- err = AEDuplicateDesc(&AEDESC_OF(res), toDesc);
817
- return err;
806
+ // handle_coercion method should return an AE::AEDesc, or nil if an error occurred
807
+ OSErr err = noErr;
808
+ VALUE res;
809
+
810
+ res = rb_funcall((VALUE)refcon,
811
+ rb_intern("handle_coercion"),
812
+ 2,
813
+ rbAE_wrapBorrowedAEDesc(fromDesc),
814
+ rbDescTypeToString(toType));
815
+ if (rb_obj_is_instance_of(res, cAEDesc) != Qtrue) return errAECoercionFail;
816
+ err = AEDuplicateDesc(&AEDESC_OF(res), toDesc);
817
+ return err;
818
818
  }
819
819
 
820
820
 
@@ -823,74 +823,74 @@ rbAE_GenericCoercionHandler(const AEDesc *fromDesc, DescType toType, SRefCon ref
823
823
  static VALUE
824
824
  rbAE_AEInstallCoercionHandler(VALUE self, VALUE fromType, VALUE toType, SRefCon handler)
825
825
  {
826
- /*
827
- * fromType and toType must be four-character code strings
828
- *
829
- * handler must be a Ruby object containing a method named 'handle_coercion' that takes an
830
- * AEDesc and a four-character code (original value, desired type) as arguments, and returns an
831
- * AEDesc of the desired type.Note that this object is responsible for trapping any unhandled
832
- * exceptions and returning nil (or any other non-AEDesc value) as appropriate, otherwise the
833
- * program will exit.
834
- */
835
- OSErr err = noErr;
836
-
837
- err = AEInstallCoercionHandler(rbStringToDescType(fromType),
838
- rbStringToDescType(toType),
839
- upp_GenericCoercionHandler, handler,
840
- 1, 0);
841
- if (err != noErr) rbAE_raiseMacOSError("Can't install coercion handler.", err);
842
- return Qnil;
826
+ /*
827
+ * fromType and toType must be four-character code strings
828
+ *
829
+ * handler must be a Ruby object containing a method named 'handle_coercion' that takes an
830
+ * AEDesc and a four-character code (original value, desired type) as arguments, and returns an
831
+ * AEDesc of the desired type.Note that this object is responsible for trapping any unhandled
832
+ * exceptions and returning nil (or any other non-AEDesc value) as appropriate, otherwise the
833
+ * program will exit.
834
+ */
835
+ OSErr err = noErr;
836
+
837
+ err = AEInstallCoercionHandler(rbStringToDescType(fromType),
838
+ rbStringToDescType(toType),
839
+ upp_GenericCoercionHandler, handler,
840
+ 1, 0);
841
+ if (err != noErr) rbAE_raiseMacOSError("Can't install coercion handler.", err);
842
+ return Qnil;
843
843
  }
844
844
 
845
845
 
846
846
  static VALUE
847
847
  rbAE_AERemoveCoercionHandler(VALUE self, VALUE fromType, VALUE toType)
848
848
  {
849
- OSErr err = noErr;
850
-
851
- err = AERemoveCoercionHandler(rbStringToDescType(fromType),
852
- rbStringToDescType(toType),
853
- upp_GenericCoercionHandler,
854
- 0);
855
- if (err != noErr) rbAE_raiseMacOSError("Can't remove coercion handler.", err);
856
- return Qnil;
849
+ OSErr err = noErr;
850
+
851
+ err = AERemoveCoercionHandler(rbStringToDescType(fromType),
852
+ rbStringToDescType(toType),
853
+ upp_GenericCoercionHandler,
854
+ 0);
855
+ if (err != noErr) rbAE_raiseMacOSError("Can't remove coercion handler.", err);
856
+ return Qnil;
857
857
  }
858
858
 
859
859
 
860
860
  static VALUE
861
861
  rbAE_AEGetCoercionHandler(VALUE self, VALUE fromType, VALUE toType)
862
862
  {
863
- OSErr err = noErr;
864
- AECoercionHandlerUPP handlerUPP;
865
- SRefCon handler;
866
- Boolean fromTypeIsDesc;
867
-
868
- err = AEGetCoercionHandler(rbStringToDescType(fromType),
869
- rbStringToDescType(toType),
870
- &handlerUPP, &handler,
871
- &fromTypeIsDesc,
872
- 0);
873
- if (err != noErr) rbAE_raiseMacOSError("Can't get coercion handler.", err);
874
- return rb_ary_new3(2, handler, fromTypeIsDesc ? Qtrue : Qfalse);
863
+ OSErr err = noErr;
864
+ AECoercionHandlerUPP handlerUPP;
865
+ SRefCon handler;
866
+ Boolean fromTypeIsDesc;
867
+
868
+ err = AEGetCoercionHandler(rbStringToDescType(fromType),
869
+ rbStringToDescType(toType),
870
+ &handlerUPP, &handler,
871
+ &fromTypeIsDesc,
872
+ 0);
873
+ if (err != noErr) rbAE_raiseMacOSError("Can't get coercion handler.", err);
874
+ return rb_ary_new3(2, handler, fromTypeIsDesc ? Qtrue : Qfalse);
875
875
  }
876
876
 
877
877
 
878
878
 
879
-
879
+
880
880
  /**********************************************************************/
881
881
  // Process management
882
882
  static VALUE
883
883
  rbAE_transformProcessToForegroundApplication(VALUE self)
884
884
  {
885
- OSStatus err = 0;
886
- ProcessSerialNumber psn = {0, kCurrentProcess};
887
-
888
- err = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
889
- if( err != 0) rbAE_raiseMacOSError("Can't transform process.", err);
890
- return Qnil;
885
+ OSStatus err = 0;
886
+ ProcessSerialNumber psn = {0, kCurrentProcess};
887
+
888
+ err = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
889
+ if( err != 0) rbAE_raiseMacOSError("Can't transform process.", err);
890
+ return Qnil;
891
891
  }
892
892
 
893
-
893
+
894
894
  /**********************************************************************/
895
895
  // Initialisation
896
896
 
@@ -898,82 +898,82 @@ void
898
898
  Init_ae (void)
899
899
  {
900
900
 
901
- mAE = rb_define_module("AE");
902
-
903
- // AE::AEDesc
904
-
905
- cAEDesc = rb_define_class_under(mAE, "AEDesc", rb_cObject);
906
-
907
- rb_define_singleton_method(cAEDesc, "new", rbAE_AEDesc_new, 2);
908
- rb_define_singleton_method(cAEDesc, "new_list", rbAE_AEDesc_newList, 1);
909
- rb_define_singleton_method(cAEDesc, "new_apple_event", rbAE_AEDesc_newAppleEvent, 5);
910
- rb_define_singleton_method(cAEDesc, "unflatten", rbAE_AEDesc_newUnflatten, 1);
911
-
912
- rb_define_method(cAEDesc, "to_s", rbAE_AEDesc_inspect, 0);
913
- rb_define_method(cAEDesc, "inspect", rbAE_AEDesc_inspect, 0);
914
- rb_define_method(cAEDesc, "type", rbAE_AEDesc_type, 0);
915
- rb_define_method(cAEDesc, "data", rbAE_AEDesc_data, 0);
916
- rb_define_method(cAEDesc, "flatten", rbAE_AEDesc_flatten, 0);
917
- rb_define_method(cAEDesc, "is_record?", rbAE_AEDesc_isRecord, 0);
918
- rb_define_method(cAEDesc, "coerce", rbAE_AEDesc_coerce, 1);
919
- rb_define_method(cAEDesc, "length", rbAE_AEDesc_length, 0);
920
- rb_define_method(cAEDesc, "put_item", rbAE_AEDesc_putItem, 2);
921
- rb_define_method(cAEDesc, "put_param", rbAE_AEDesc_putParam, 2);
922
- rb_define_method(cAEDesc, "put_attr", rbAE_AEDesc_putAttr, 2);
923
- rb_define_method(cAEDesc, "get_item", rbAE_AEDesc_getItem, 2);
924
- rb_define_method(cAEDesc, "get_param", rbAE_AEDesc_getParam, 2);
925
- rb_define_method(cAEDesc, "get_attr", rbAE_AEDesc_getAttr, 2);
926
- rb_define_method(cAEDesc, "send", rbAE_AEDesc_send, 2);
927
- rb_define_method(cAEDesc, "send_thread_safe", rbAE_AEDesc_sendThreadSafe, 2);
928
-
929
- // AE::MacOSError
930
-
931
- cMacOSError = rb_define_class_under(mAE, "MacOSError", rb_eStandardError);
932
-
933
- rb_define_attr(cMacOSError, "number", Qtrue, Qfalse);
934
- rb_define_attr(cMacOSError, "description", Qtrue, Qfalse);
935
-
936
- rb_define_alias(cMacOSError, "to_i", "number");
937
-
938
- rb_define_method(cMacOSError, "to_s", rbAE_MacOSError_inspect, 0);
939
- rb_define_method(cMacOSError, "inspect", rbAE_MacOSError_inspect, 0);
940
-
941
- // Support functions
942
-
943
- rb_define_module_function(mAE, "find_application", rbAE_findApplication, 3);
944
- rb_define_module_function(mAE, "psn_for_application_path", rbAE_psnForApplicationPath, 1);
945
- rb_define_module_function(mAE, "psn_for_process_id", rbAE_psnForPID, 1);
946
- rb_define_module_function(mAE, "launch_application", rbAE_launchApplication, 3);
947
-
948
- rb_define_module_function(mAE, "convert_path_to_url",
949
- rbAE_convertPathToURL, 2);
950
- rb_define_module_function(mAE, "convert_url_to_path",
951
- rbAE_convertURLToPath, 2);
952
-
953
- rb_define_module_function(mAE, "convert_long_date_time_to_string",
954
- rbAE_convertLongDateTimeToString, 1);
955
- rb_define_module_function(mAE, "convert_string_to_long_date_time",
956
- rbAE_convertStringToLongDateTime, 1);
957
- rb_define_module_function(mAE, "convert_long_date_time_to_unix_seconds",
958
- rbAE_convertLongDateTimeToUnixSeconds, 1);
959
- rb_define_module_function(mAE, "convert_unix_seconds_to_long_date_time",
960
- rbAE_convertUnixSecondsToLongDateTime, 1);
961
-
962
- rb_define_module_function(mAE, "copy_scripting_definition", rbAE_OSACopyScriptingDefinition, 1);
963
-
964
- // Event handling
965
-
966
- upp_GenericEventHandler = NewAEEventHandlerUPP(rbAE_GenericEventHandler);
967
- upp_GenericCoercionHandler = NewAECoerceDescUPP(rbAE_GenericCoercionHandler);
968
-
969
- rb_define_module_function(mAE, "install_event_handler", rbAE_AEInstallEventHandler, 3);
970
- rb_define_module_function(mAE, "remove_event_handler", rbAE_AERemoveEventHandler, 2);
971
- rb_define_module_function(mAE, "get_event_handler", rbAE_AEGetEventHandler, 2);
972
-
973
- rb_define_module_function(mAE, "install_coercion_handler", rbAE_AEInstallCoercionHandler, 3);
974
- rb_define_module_function(mAE, "remove_coercion_handler", rbAE_AERemoveCoercionHandler, 2);
975
- rb_define_module_function(mAE, "get_coercion_handler", rbAE_AEGetCoercionHandler, 2);
976
-
977
- rb_define_module_function(mAE, "transform_process_to_foreground_application",
978
- rbAE_transformProcessToForegroundApplication, 0);
901
+ mAE = rb_define_module("AE");
902
+
903
+ // AE::AEDesc
904
+
905
+ cAEDesc = rb_define_class_under(mAE, "AEDesc", rb_cObject);
906
+
907
+ rb_define_singleton_method(cAEDesc, "new", rbAE_AEDesc_new, 2);
908
+ rb_define_singleton_method(cAEDesc, "new_list", rbAE_AEDesc_newList, 1);
909
+ rb_define_singleton_method(cAEDesc, "new_apple_event", rbAE_AEDesc_newAppleEvent, 5);
910
+ rb_define_singleton_method(cAEDesc, "unflatten", rbAE_AEDesc_newUnflatten, 1);
911
+
912
+ rb_define_method(cAEDesc, "to_s", rbAE_AEDesc_inspect, 0);
913
+ rb_define_method(cAEDesc, "inspect", rbAE_AEDesc_inspect, 0);
914
+ rb_define_method(cAEDesc, "type", rbAE_AEDesc_type, 0);
915
+ rb_define_method(cAEDesc, "data", rbAE_AEDesc_data, 0);
916
+ rb_define_method(cAEDesc, "flatten", rbAE_AEDesc_flatten, 0);
917
+ rb_define_method(cAEDesc, "is_record?", rbAE_AEDesc_isRecord, 0);
918
+ rb_define_method(cAEDesc, "coerce", rbAE_AEDesc_coerce, 1);
919
+ rb_define_method(cAEDesc, "length", rbAE_AEDesc_length, 0);
920
+ rb_define_method(cAEDesc, "put_item", rbAE_AEDesc_putItem, 2);
921
+ rb_define_method(cAEDesc, "put_param", rbAE_AEDesc_putParam, 2);
922
+ rb_define_method(cAEDesc, "put_attr", rbAE_AEDesc_putAttr, 2);
923
+ rb_define_method(cAEDesc, "get_item", rbAE_AEDesc_getItem, 2);
924
+ rb_define_method(cAEDesc, "get_param", rbAE_AEDesc_getParam, 2);
925
+ rb_define_method(cAEDesc, "get_attr", rbAE_AEDesc_getAttr, 2);
926
+ rb_define_method(cAEDesc, "send", rbAE_AEDesc_send, 2);
927
+ rb_define_method(cAEDesc, "send_thread_safe", rbAE_AEDesc_sendThreadSafe, 2);
928
+
929
+ // AE::MacOSError
930
+
931
+ cMacOSError = rb_define_class_under(mAE, "MacOSError", rb_eStandardError);
932
+
933
+ rb_define_attr(cMacOSError, "number", Qtrue, Qfalse);
934
+ rb_define_attr(cMacOSError, "description", Qtrue, Qfalse);
935
+
936
+ rb_define_alias(cMacOSError, "to_i", "number");
937
+
938
+ rb_define_method(cMacOSError, "to_s", rbAE_MacOSError_inspect, 0);
939
+ rb_define_method(cMacOSError, "inspect", rbAE_MacOSError_inspect, 0);
940
+
941
+ // Support functions
942
+
943
+ rb_define_module_function(mAE, "find_application", rbAE_findApplication, 3);
944
+ rb_define_module_function(mAE, "psn_for_application_path", rbAE_psnForApplicationPath, 1);
945
+ rb_define_module_function(mAE, "psn_for_process_id", rbAE_psnForPID, 1);
946
+ rb_define_module_function(mAE, "launch_application", rbAE_launchApplication, 3);
947
+
948
+ rb_define_module_function(mAE, "convert_path_to_url",
949
+ rbAE_convertPathToURL, 2);
950
+ rb_define_module_function(mAE, "convert_url_to_path",
951
+ rbAE_convertURLToPath, 2);
952
+
953
+ rb_define_module_function(mAE, "convert_long_date_time_to_string",
954
+ rbAE_convertLongDateTimeToString, 1);
955
+ rb_define_module_function(mAE, "convert_string_to_long_date_time",
956
+ rbAE_convertStringToLongDateTime, 1);
957
+ rb_define_module_function(mAE, "convert_long_date_time_to_unix_seconds",
958
+ rbAE_convertLongDateTimeToUnixSeconds, 1);
959
+ rb_define_module_function(mAE, "convert_unix_seconds_to_long_date_time",
960
+ rbAE_convertUnixSecondsToLongDateTime, 1);
961
+
962
+ rb_define_module_function(mAE, "copy_scripting_definition", rbAE_OSACopyScriptingDefinition, 1);
963
+
964
+ // Event handling
965
+
966
+ upp_GenericEventHandler = NewAEEventHandlerUPP(rbAE_GenericEventHandler);
967
+ upp_GenericCoercionHandler = NewAECoerceDescUPP(rbAE_GenericCoercionHandler);
968
+
969
+ rb_define_module_function(mAE, "install_event_handler", rbAE_AEInstallEventHandler, 3);
970
+ rb_define_module_function(mAE, "remove_event_handler", rbAE_AERemoveEventHandler, 2);
971
+ rb_define_module_function(mAE, "get_event_handler", rbAE_AEGetEventHandler, 2);
972
+
973
+ rb_define_module_function(mAE, "install_coercion_handler", rbAE_AEInstallCoercionHandler, 3);
974
+ rb_define_module_function(mAE, "remove_coercion_handler", rbAE_AERemoveCoercionHandler, 2);
975
+ rb_define_module_function(mAE, "get_coercion_handler", rbAE_AEGetCoercionHandler, 2);
976
+
977
+ rb_define_module_function(mAE, "transform_process_to_foreground_application",
978
+ rbAE_transformProcessToForegroundApplication, 0);
979
979
  }