rb-appscript 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGES +37 -0
  2. data/LICENSE +6 -2
  3. data/README +7 -4
  4. data/TODO +6 -2
  5. data/doc/aem-manual/01_introduction.html +1 -1
  6. data/doc/aem-manual/02_apioverview.html +1 -1
  7. data/doc/aem-manual/03_packingandunpackingdata.html +3 -3
  8. data/doc/aem-manual/04_references.html +18 -13
  9. data/doc/aem-manual/05_targettingapplications.html +33 -13
  10. data/doc/aem-manual/06_buildingandsendingevents.html +1 -1
  11. data/doc/aem-manual/07_findapp.html +1 -1
  12. data/doc/aem-manual/08_examples.html +1 -1
  13. data/doc/aem-manual/index.html +1 -1
  14. data/doc/appscript-manual/01_introduction.html +1 -1
  15. data/doc/appscript-manual/02_aboutappscripting.html +4 -4
  16. data/doc/appscript-manual/03_quicktutorial.html +1 -1
  17. data/doc/appscript-manual/04_gettinghelp.html +13 -42
  18. data/doc/appscript-manual/05_keywordconversion.html +1 -1
  19. data/doc/appscript-manual/06_classesandenums.html +1 -1
  20. data/doc/appscript-manual/07_applicationobjects.html +19 -1
  21. data/doc/appscript-manual/08_realvsgenericreferences.html +1 -1
  22. data/doc/appscript-manual/09_referenceforms.html +1 -1
  23. data/doc/appscript-manual/10_referenceexamples.html +1 -1
  24. data/doc/appscript-manual/11_applicationcommands.html +1 -1
  25. data/doc/appscript-manual/12_commandexamples.html +1 -1
  26. data/doc/appscript-manual/13_performanceissues.html +1 -1
  27. data/doc/appscript-manual/14_notes.html +1 -1
  28. data/doc/appscript-manual/index.html +1 -1
  29. data/doc/index.html +1 -1
  30. data/doc/mactypes-manual/index.html +13 -1
  31. data/doc/osax-manual/index.html +37 -6
  32. data/extconf.rb +2 -2
  33. data/rb-appscript.gemspec +1 -1
  34. data/sample/AB_export_vcard.rb +31 -0
  35. data/sample/Add_iCal_event.rb +4 -4
  36. data/src/lib/_aem/connect.rb +88 -8
  37. data/src/lib/_aem/mactypes.rb +27 -21
  38. data/src/lib/_appscript/reservedkeywords.rb +1 -0
  39. data/src/lib/aem.rb +40 -5
  40. data/src/lib/appscript.rb +104 -30
  41. data/src/lib/kae.rb +1 -0
  42. data/src/lib/osax.rb +35 -19
  43. data/src/rbae.c +115 -1
  44. data/test/README +3 -1
  45. data/test/test_appscriptcommands.rb +5 -4
  46. data/test/test_codecs.rb +7 -1
  47. data/test/testall.sh +1 -1
  48. metadata +24 -23
data/src/rbae.c CHANGED
@@ -493,6 +493,18 @@ rbAE_psnForApplicationPath(VALUE self, VALUE path)
493
493
  }
494
494
 
495
495
 
496
+ static VALUE
497
+ rbAE_psnForPID(VALUE self, VALUE pid)
498
+ {
499
+ OSStatus err = noErr;
500
+ ProcessSerialNumber psn = {0, kNoProcess};
501
+
502
+ err = GetProcessForPID(NUM2INT(pid), &psn);
503
+ if (err != 0) rbAE_raiseMacOSError("Can't get next process.", err); // -600 if process not found
504
+ return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
505
+ }
506
+
507
+
496
508
  static VALUE
497
509
  rbAE_launchApplication(VALUE self, VALUE path, VALUE firstEvent, VALUE flags)
498
510
  {
@@ -535,6 +547,98 @@ rbAE_launchApplication(VALUE self, VALUE path, VALUE firstEvent, VALUE flags)
535
547
  return rb_ary_new3(2, INT2NUM(psn.highLongOfPSN), INT2NUM(psn.lowLongOfPSN));
536
548
  }
537
549
 
550
+ /**********************************************************************/
551
+ // HFS/POSIX path conversions
552
+
553
+ static VALUE
554
+ rbAE_convertPOSIXPathToURL(VALUE self, VALUE path)
555
+ {
556
+ CFURLRef url;
557
+ UInt8 buffer[PATH_MAX];
558
+
559
+ url = CFURLCreateFromFileSystemRepresentation(NULL,
560
+ (UInt8 *)(RSTRING(path)->ptr),
561
+ (CFIndex)(RSTRING(path)->len),
562
+ false);
563
+ if (url == NULL) rb_raise(rb_eRuntimeError, "Invalid POSIX path string.");
564
+ buffer[CFURLGetBytes(url, buffer, PATH_MAX - 1)] = '\0';
565
+ CFRelease(url);
566
+ return rb_str_new2((char *)buffer);
567
+ }
568
+
569
+ static VALUE
570
+ rbAE_convertHFSPathToURL(VALUE self, VALUE path)
571
+ {
572
+ CFStringRef str;
573
+ CFURLRef url;
574
+ UInt8 buffer[PATH_MAX];
575
+
576
+ str = CFStringCreateWithBytes(NULL,
577
+ (UInt8 *)(RSTRING(path)->ptr),
578
+ (CFIndex)(RSTRING(path)->len),
579
+ kCFStringEncodingUTF8,
580
+ false);
581
+ if (str == NULL) rb_raise(rb_eRuntimeError, "Invalid HFS path string.");
582
+ url = CFURLCreateWithFileSystemPath(NULL,
583
+ str,
584
+ kCFURLHFSPathStyle,
585
+ false);
586
+ CFRelease(str);
587
+ if (url == NULL) rb_raise(rb_eRuntimeError, "Invalid HFS path string.");
588
+ buffer[CFURLGetBytes(url, buffer, PATH_MAX - 1)] = '\0';
589
+ CFRelease(url);
590
+ return rb_str_new2((char *)buffer);
591
+ }
592
+
593
+ static VALUE
594
+ rbAE_convertURLToPOSIXPath(VALUE self, VALUE urlStr)
595
+ {
596
+ Boolean err;
597
+ CFURLRef url;
598
+ UInt8 buffer[PATH_MAX];
599
+
600
+ url = CFURLCreateWithBytes(NULL,
601
+ (UInt8 *)(RSTRING(urlStr)->ptr),
602
+ (CFIndex)(RSTRING(urlStr)->len),
603
+ kCFStringEncodingUTF8,
604
+ NULL);
605
+ if (url == NULL) rb_raise(rb_eRuntimeError, "Invalid URL string.");
606
+ err = CFURLGetFileSystemRepresentation(url,
607
+ true,
608
+ buffer,
609
+ PATH_MAX);
610
+ CFRelease(url);
611
+ if (!err) rb_raise(rb_eRuntimeError, "Can't get POSIX path.");
612
+ return rb_str_new2((char *)buffer);
613
+ }
614
+
615
+ static VALUE
616
+ rbAE_convertURLToHFSPath(VALUE self, VALUE urlStr)
617
+ {
618
+ Boolean err;
619
+ CFURLRef url;
620
+ CFStringRef str;
621
+ char buffer[PATH_MAX];
622
+
623
+ url = CFURLCreateWithBytes(NULL,
624
+ (UInt8 *)(RSTRING(urlStr)->ptr),
625
+ (CFIndex)(RSTRING(urlStr)->len),
626
+ kCFStringEncodingUTF8,
627
+ NULL);
628
+ if (url == NULL) rb_raise(rb_eRuntimeError, "Invalid URL string.");
629
+ str = CFURLCopyFileSystemPath(url, kCFURLHFSPathStyle);
630
+ CFRelease(url);
631
+ if (str == NULL) rb_raise(rb_eRuntimeError, "Can't get HFS path.");
632
+ err = CFStringGetCString(str,
633
+ buffer,
634
+ PATH_MAX,
635
+ kCFStringEncodingUTF8);
636
+ CFRelease(str);
637
+ if (!err) rb_raise(rb_eRuntimeError, "Can't get HFS path.");
638
+ return rb_str_new2(buffer);
639
+ }
640
+
641
+
538
642
  /**********************************************************************/
539
643
  // Date conversion
540
644
 
@@ -544,7 +648,7 @@ rbAE_convertLongDateTimeToUnixSeconds(VALUE self, VALUE ldt)
544
648
  OSStatus err = 0;
545
649
  CFAbsoluteTime cfTime;
546
650
 
547
- err = UCConvertLongDateTimeToCFAbsoluteTime(rb_big2ll(ldt), &cfTime);
651
+ err = UCConvertLongDateTimeToCFAbsoluteTime(NUM2LL(ldt), &cfTime);
548
652
  if (err != noErr) rbAE_raiseMacOSError("Can't convert LongDateTime to seconds.", err);
549
653
  return rb_float_new(cfTime + kCFAbsoluteTimeIntervalSince1970);
550
654
  }
@@ -844,7 +948,17 @@ Init_ae (void)
844
948
 
845
949
  rb_define_module_function(mAE, "find_application", rbAE_findApplication, 3);
846
950
  rb_define_module_function(mAE, "psn_for_application_path", rbAE_psnForApplicationPath, 1);
951
+ rb_define_module_function(mAE, "psn_for_process_id", rbAE_psnForPID, 1);
847
952
  rb_define_module_function(mAE, "launch_application", rbAE_launchApplication, 3);
953
+
954
+ rb_define_module_function(mAE, "convert_posix_path_to_url",
955
+ rbAE_convertPOSIXPathToURL, 1);
956
+ rb_define_module_function(mAE, "convert_hfs_path_to_url",
957
+ rbAE_convertHFSPathToURL, 1);
958
+ rb_define_module_function(mAE, "convert_url_to_posix_path",
959
+ rbAE_convertURLToPOSIXPath, 1);
960
+ rb_define_module_function(mAE, "convert_url_to_hfs_path",
961
+ rbAE_convertURLToHFSPath, 1);
848
962
 
849
963
  rb_define_module_function(mAE, "convert_long_date_time_to_unix_seconds",
850
964
  rbAE_convertLongDateTimeToUnixSeconds, 1);
@@ -1 +1,3 @@
1
- Some of the code in these tests may not yet be 100% portable (hardcoded paths, etc) so may currently fail for some users, although they have passed for Ruby 1.8.x on OS X 10.3.9 and OS X 10.4.x (PPC & i386).
1
+ Some of the code in these tests may not yet be 100% portable (hardcoded paths, etc) so may currently fail for some users, although they have passed for Ruby 1.8.x on OS X 10.3.9, OS X 10.4.x (PPC & i386) and OS X 10.5.1 (i386).
2
+
3
+ Note that some mactypes unit tests may fail as Alias and FileURL comparisons are rather dumb and don't normalise path strings before comparing/hashing. Future releases may try to remedy this.
@@ -3,10 +3,11 @@
3
3
  require 'test/unit'
4
4
  require 'appscript'
5
5
 
6
- class AS_SafeObject
7
- def self.hide(name)
8
- end
9
- end
6
+ # rb-appscript 0.5.0+ should no longer require the following kludge:
7
+ #class AS_SafeObject
8
+ # def self.hide(name)
9
+ # end
10
+ #end
10
11
 
11
12
  class TC_AppscriptNewApp < Test::Unit::TestCase
12
13
 
@@ -119,7 +119,7 @@ class TC_Codecs < Test::Unit::TestCase
119
119
  end
120
120
 
121
121
  def test_file
122
- path = '/Applications/TextEdit.app/'
122
+ path = '/Applications/TextEdit.app'
123
123
  d = @c.pack(MacTypes::Alias.path(path))
124
124
  assert_equal(path, @c.unpack(d).to_s)
125
125
 
@@ -169,4 +169,10 @@ class TC_Codecs < Test::Unit::TestCase
169
169
  assert_equal(:inches, val2.type)
170
170
  assert_equal(3.3, val2.value)
171
171
  end
172
+
173
+ def test_app
174
+ val = AEM::Application.by_path(FindApp.by_name('TextEdit'))
175
+ d = @c.pack(val)
176
+ assert_equal(KAE::TypeProcessSerialNumber, d.type)
177
+ end
172
178
  end
@@ -3,7 +3,7 @@
3
3
  for f in `ls | grep '^test_'`;
4
4
  do
5
5
  echo $f
6
- /usr/local/bin/ruby -w $f
6
+ /usr/bin/ruby -w $f
7
7
  echo
8
8
  echo
9
9
  done
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rb-appscript
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2007-08-17 00:00:00 +01:00
6
+ version: 0.5.0
7
+ date: 2007-12-20 00:00:00 +00:00
8
8
  summary: Ruby appscript (rb-appscript) is a high-level, user-friendly Apple event bridge that allows you to control scriptable Mac OS X applications using ordinary Ruby scripts.
9
9
  require_paths:
10
10
  - lib
@@ -31,19 +31,7 @@ authors:
31
31
  files:
32
32
  - CHANGES
33
33
  - doc
34
- - extconf.rb
35
- - LICENSE
36
- - rb-appscript.gemspec
37
- - README
38
- - sample
39
- - src
40
- - test
41
- - TODO
42
34
  - doc/aem-manual
43
- - doc/appscript-manual
44
- - doc/index.html
45
- - doc/mactypes-manual
46
- - doc/osax-manual
47
35
  - doc/aem-manual/01_introduction.html
48
36
  - doc/aem-manual/02_apioverview.html
49
37
  - doc/aem-manual/03_packingandunpackingdata.html
@@ -55,6 +43,7 @@ files:
55
43
  - doc/aem-manual/aemreferenceinheritance.gif
56
44
  - doc/aem-manual/full.css
57
45
  - doc/aem-manual/index.html
46
+ - doc/appscript-manual
58
47
  - doc/appscript-manual/01_introduction.html
59
48
  - doc/appscript-manual/02_aboutappscripting.html
60
49
  - doc/appscript-manual/03_quicktutorial.html
@@ -76,8 +65,17 @@ files:
76
65
  - doc/appscript-manual/index.html
77
66
  - doc/appscript-manual/relationships_example.gif
78
67
  - doc/appscript-manual/ruby_to_itunes_event.gif
68
+ - doc/index.html
69
+ - doc/mactypes-manual
79
70
  - doc/mactypes-manual/index.html
71
+ - doc/osax-manual
80
72
  - doc/osax-manual/index.html
73
+ - extconf.rb
74
+ - LICENSE
75
+ - rb-appscript.gemspec
76
+ - README
77
+ - sample
78
+ - sample/AB_export_vcard.rb
81
79
  - sample/AB_list_people_with_emails.rb
82
80
  - sample/Add_iCal_event.rb
83
81
  - sample/Create_daily_iCal_todos.rb
@@ -94,16 +92,9 @@ files:
94
92
  - sample/Simple_Finder_GUI_Scripting.rb
95
93
  - sample/Stagger_Finder_windows.rb
96
94
  - sample/TextEdit_demo.rb
95
+ - src
97
96
  - src/lib
98
- - src/rbae.c
99
- - src/SendThreadSafe.c
100
- - src/SendThreadSafe.h
101
97
  - src/lib/_aem
102
- - src/lib/_appscript
103
- - src/lib/aem.rb
104
- - src/lib/appscript.rb
105
- - src/lib/kae.rb
106
- - src/lib/osax.rb
107
98
  - src/lib/_aem/aemreference.rb
108
99
  - src/lib/_aem/codecs.rb
109
100
  - src/lib/_aem/connect.rb
@@ -111,11 +102,20 @@ files:
111
102
  - src/lib/_aem/mactypes.rb
112
103
  - src/lib/_aem/send.rb
113
104
  - src/lib/_aem/typewrappers.rb
105
+ - src/lib/_appscript
114
106
  - src/lib/_appscript/defaultterminology.rb
115
107
  - src/lib/_appscript/referencerenderer.rb
116
108
  - src/lib/_appscript/reservedkeywords.rb
117
109
  - src/lib/_appscript/safeobject.rb
118
110
  - src/lib/_appscript/terminology.rb
111
+ - src/lib/aem.rb
112
+ - src/lib/appscript.rb
113
+ - src/lib/kae.rb
114
+ - src/lib/osax.rb
115
+ - src/rbae.c
116
+ - src/SendThreadSafe.c
117
+ - src/SendThreadSafe.h
118
+ - test
119
119
  - test/README
120
120
  - test/test_aemreference.rb
121
121
  - test/test_appscriptcommands.rb
@@ -125,6 +125,7 @@ files:
125
125
  - test/test_mactypes.rb
126
126
  - test/test_osax.rb
127
127
  - test/testall.sh
128
+ - TODO
128
129
  test_files:
129
130
  - test/test_aemreference.rb
130
131
  - test/test_appscriptcommands.rb