rb-appscript 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGES +59 -0
  2. data/LICENSE +65 -0
  3. data/README +1 -1
  4. data/TODO +13 -13
  5. data/doc/aem-manual/04_references.html +13 -13
  6. data/doc/aem-manual/05_targettingapplications.html +7 -5
  7. data/doc/aem-manual/06_buildingandsendingevents.html +1 -1
  8. data/doc/aem-manual/08_examples.html +6 -6
  9. data/doc/aem-manual/index.html +3 -4
  10. data/doc/appscript-manual/02_aboutappscripting.html +2 -10
  11. data/doc/appscript-manual/04_gettinghelp.html +32 -18
  12. data/doc/appscript-manual/05_keywordconversion.html +7 -7
  13. data/doc/appscript-manual/06_classesandenums.html +2 -21
  14. data/doc/appscript-manual/07_applicationobjects.html +11 -2
  15. data/doc/appscript-manual/08_realvsgenericreferences.html +1 -1
  16. data/doc/appscript-manual/09_referenceforms.html +13 -13
  17. data/doc/appscript-manual/10_referenceexamples.html +7 -7
  18. data/doc/appscript-manual/11_applicationcommands.html +30 -28
  19. data/doc/appscript-manual/13_performanceissues.html +3 -3
  20. data/doc/appscript-manual/{15_notes.html → 14_notes.html} +18 -13
  21. data/doc/appscript-manual/full.css +1 -2
  22. data/doc/appscript-manual/index.html +3 -4
  23. data/doc/index.html +2 -1
  24. data/doc/mactypes-manual/index.html +23 -13
  25. data/doc/osax-manual/index.html +27 -5
  26. data/rb-appscript.gemspec +1 -1
  27. data/sample/AB_list_people_with_emails.rb +2 -1
  28. data/sample/Add_iCal_event.rb +18 -0
  29. data/sample/Export_Address_Book_phone_numbers.rb +56 -0
  30. data/sample/Hello_world.rb +9 -1
  31. data/sample/Select_all_HTML_files.rb +4 -2
  32. data/sample/iTunes_top40_to_html.rb +7 -4
  33. data/src/lib/_aem/aemreference.rb +50 -51
  34. data/src/lib/_aem/codecs.rb +148 -178
  35. data/src/lib/_aem/connect.rb +0 -2
  36. data/src/lib/_aem/findapp.rb +1 -1
  37. data/src/lib/_aem/mactypes.rb +2 -9
  38. data/src/lib/_aem/send.rb +2 -2
  39. data/src/lib/_appscript/defaultterminology.rb +2 -2
  40. data/src/lib/_appscript/referencerenderer.rb +119 -14
  41. data/src/lib/_appscript/reservedkeywords.rb +5 -0
  42. data/src/lib/_appscript/safeobject.rb +190 -0
  43. data/src/lib/_appscript/terminology.rb +195 -90
  44. data/src/lib/aem.rb +8 -9
  45. data/src/lib/appscript.rb +175 -159
  46. data/src/lib/osax.rb +65 -29
  47. data/src/rbae.c +42 -2
  48. data/test/test_aemreference.rb +3 -3
  49. data/test/test_appscriptcommands.rb +135 -0
  50. data/test/test_appscriptreference.rb +10 -8
  51. data/test/test_mactypes.rb +7 -1
  52. data/test/test_osax.rb +57 -0
  53. data/test/testall.sh +2 -1
  54. metadata +10 -9
  55. data/doc/aem-manual/09_notes.html +0 -41
  56. data/doc/appscript-manual/14_problemapps.html +0 -192
  57. data/misc/adobeunittypes.rb +0 -14
  58. data/misc/dump.rb +0 -72
  59. data/rb-appscript-0.2.0.gem +0 -0
data/test/test_osax.rb ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'test/unit'
4
+ require 'osax'
5
+
6
+ class AS_SafeObject
7
+ def self.hide(name)
8
+ end
9
+ end
10
+
11
+ class TC_OSAX < Test::Unit::TestCase
12
+
13
+ def test_1
14
+ sa = OSAX.osax('Standardadditions')
15
+
16
+ assert_equal(65, sa.ASCII_number('A'))
17
+
18
+ assert_equal(MacTypes::Alias.path("/Applications/"), sa.path_to(:applications_folder))
19
+
20
+ assert_equal(MacTypes::Alias.path("/Library/Scripts/"),
21
+ sa.path_to(:scripts_folder, :from=>:local_domain))
22
+
23
+ assert_raises(RuntimeError) { sa.non_existent_command }
24
+ end
25
+
26
+ def test_2
27
+ sa = OSAX.osax('Standardadditions').by_name('Finder')
28
+ assert_equal(65, sa.ASCII_number('A'))
29
+ assert_equal(MacTypes::Alias.path("/System/Library/CoreServices/Finder.app/"), sa.path_to(nil))
30
+ end
31
+
32
+ def test_3
33
+ sa = OSAX.osax('Standardadditions').by_creator('MACS')
34
+ assert_equal(65, sa.ASCII_number('A'))
35
+ assert_equal(MacTypes::Alias.path("/System/Library/CoreServices/Finder.app/"), sa.path_to(nil))
36
+ end
37
+
38
+ def test_4
39
+ sa = OSAX.osax('Standardadditions').by_id('com.apple.finder')
40
+ assert_equal(65, sa.ASCII_number('A'))
41
+ assert_equal(MacTypes::Alias.path("/System/Library/CoreServices/Finder.app/"), sa.path_to(nil))
42
+ end
43
+
44
+ def test_5
45
+ sa = OSAX.osax('Standardadditions').by_pid(`top -l1 | grep Finder | awk '{ print $1 }'`.to_i)
46
+ assert_equal(MacTypes::Alias.path("/System/Library/CoreServices/Finder.app/"), sa.path_to(nil))
47
+ assert_equal(65, sa.ASCII_number('A'))
48
+ end
49
+
50
+ def test_6
51
+ sa = OSAX.osax('Standardadditions').by_aem_app(AEM::Application.by_path("/System/Library/CoreServices/Finder.app/"))
52
+ assert_equal(65, sa.ASCII_number('A'))
53
+ assert_equal(MacTypes::Alias.path("/System/Library/CoreServices/Finder.app/"), sa.path_to(nil))
54
+ end
55
+
56
+
57
+ end
data/test/testall.sh CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/bin/bash
2
2
 
3
- for f in `ls | grep test_`;
3
+ for f in `ls | grep '^test_'`;
4
4
  do
5
+ echo $f
5
6
  /usr/local/bin/ruby $f
6
7
  echo
7
8
  echo
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rb-appscript
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
7
- date: 2006-11-30 00:00:00 +00:00
6
+ version: 0.3.0
7
+ date: 2007-01-18 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
@@ -33,8 +33,6 @@ files:
33
33
  - doc
34
34
  - extconf.rb
35
35
  - LICENSE
36
- - misc
37
- - rb-appscript-0.2.0.gem
38
36
  - rb-appscript.gemspec
39
37
  - README
40
38
  - sample
@@ -54,7 +52,6 @@ files:
54
52
  - doc/aem-manual/06_buildingandsendingevents.html
55
53
  - doc/aem-manual/07_findapp.html
56
54
  - doc/aem-manual/08_examples.html
57
- - doc/aem-manual/09_notes.html
58
55
  - doc/aem-manual/aemreferenceinheritance.gif
59
56
  - doc/aem-manual/full.css
60
57
  - doc/aem-manual/index.html
@@ -71,8 +68,7 @@ files:
71
68
  - doc/appscript-manual/11_applicationcommands.html
72
69
  - doc/appscript-manual/12_commandexamples.html
73
70
  - doc/appscript-manual/13_performanceissues.html
74
- - doc/appscript-manual/14_problemapps.html
75
- - doc/appscript-manual/15_notes.html
71
+ - doc/appscript-manual/14_notes.html
76
72
  - doc/appscript-manual/application_architecture.gif
77
73
  - doc/appscript-manual/application_architecture2.gif
78
74
  - doc/appscript-manual/finder_to_textedit_event.gif
@@ -82,10 +78,10 @@ files:
82
78
  - doc/appscript-manual/ruby_to_itunes_event.gif
83
79
  - doc/mactypes-manual/index.html
84
80
  - doc/osax-manual/index.html
85
- - misc/adobeunittypes.rb
86
- - misc/dump.rb
87
81
  - sample/AB_list_people_with_emails.rb
82
+ - sample/Add_iCal_event.rb
88
83
  - sample/Create_daily_iCal_todos.rb
84
+ - sample/Export_Address_Book_phone_numbers.rb
89
85
  - sample/Hello_world.rb
90
86
  - sample/iTunes_top40_to_html.rb
91
87
  - sample/List_iTunes_playlist_names.rb
@@ -116,20 +112,25 @@ files:
116
112
  - src/lib/_appscript/defaultterminology.rb
117
113
  - src/lib/_appscript/referencerenderer.rb
118
114
  - src/lib/_appscript/reservedkeywords.rb
115
+ - src/lib/_appscript/safeobject.rb
119
116
  - src/lib/_appscript/terminology.rb
120
117
  - test/README
121
118
  - test/test_aemreference.rb
119
+ - test/test_appscriptcommands.rb
122
120
  - test/test_appscriptreference.rb
123
121
  - test/test_codecs.rb
124
122
  - test/test_findapp.rb
125
123
  - test/test_mactypes.rb
124
+ - test/test_osax.rb
126
125
  - test/testall.sh
127
126
  test_files:
128
127
  - test/test_aemreference.rb
128
+ - test/test_appscriptcommands.rb
129
129
  - test/test_appscriptreference.rb
130
130
  - test/test_codecs.rb
131
131
  - test/test_findapp.rb
132
132
  - test/test_mactypes.rb
133
+ - test/test_osax.rb
133
134
  rdoc_options: []
134
135
 
135
136
  extra_rdoc_files: []
@@ -1,41 +0,0 @@
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>aem | 9. Notes</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>9. Notes</h1>
14
-
15
- <!-- top navigation -->
16
- <div class="navbar">
17
- <a href="08_examples.html">Previous</a> | <a href="index.html">Up</a>
18
- </div>
19
-
20
- <!-- content -->
21
- <div id="content">
22
-
23
-
24
- <h2>Copyright</h2>
25
-
26
- <p>(C) 2006 HAS -- hhas -at- users - sourceforge - net (<a href="http://rb-appscript.rubyforge.org">http://rb-appscript.rubyforge.org</a>)</p>
27
-
28
- <p>Released under the MIT License.</p>
29
-
30
-
31
- </div>
32
-
33
- <!-- bottom navigation -->
34
- <div class="navbar">
35
- <a href="08_examples.html">Previous</a> | <a href="index.html">Up</a>
36
- </div>
37
-
38
- <!--footer-->
39
- <p class="footer">&copy; 2006 HAS</p>
40
- </body>
41
- </html>
@@ -1,192 +0,0 @@
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>appscript | 14. Dealing With Problem Applications</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>14. Dealing With Problem Applications</h1>
14
-
15
- <!-- top navigation -->
16
- <div class="navbar">
17
- <a href="13_performanceissues.html">Previous</a> | <a href="index.html">Up</a> | <a href="15_notes.html">Next</a>
18
-
19
- </div>
20
-
21
- <!-- content -->
22
- <div id="content">
23
-
24
- <p>Appscript provides a number of mechanisms for dealing with problematic applications. The following topics are currently covered:</p>
25
-
26
- <ul>
27
- <li><a href="#defective_terminology">Dealing with defective terminology</a></li>
28
- <li><a href="#non_stay_open_applications">Scripting non-stay-open applications</a></li>
29
- </ul>
30
-
31
-
32
- <!-- TO DO:
33
- - patching AS_app_data codecs
34
- - adding application-specific unit types
35
- - FSRef/FileURL/FSSpec, string/unicode/international text compatibility issues with older apps
36
- -->
37
-
38
-
39
- <h2><a name="defective_terminology"></a>Dealing with defective terminology</h2>
40
-
41
-
42
- <p>There are two ways to work around missing or incorrect terminology: use <code>aem</code> or use the <code>dump</code> tool.</p>
43
-
44
- <h3>Use aem</h3>
45
-
46
-
47
- <p>If faulty terminology prevents you from correctly constructing an appscript reference or command, one solution is to use the lower-level aem module, which uses raw codes instead of human-readable names. (You can use the <a href="http://sourceforge.net/project/showfiles.php?group_id=175009">ASDictionary</a> application to obtain a plain text listing of raw codes from an application's terminology resource.)</p>
48
-
49
- <p>Note that you can obtain an aem reference from an existing appscript reference by calling its <code>AS_aem_reference</code> method. You can also pass an aem reference as a parameter to an appscript command. (You cannot use an appscript reference in an aem event, however; you have to extract its aem reference and use that.)</p>
50
-
51
- <p>For example:</p>
52
-
53
- <pre><code>aem_ref = app('TextEdit').documents[1].text.AS_aem_reference
54
-
55
- # aem_ref contains an aem reference:
56
- # app.elements('docu').by_index(1).elements('ctxt')
57
-
58
- app('TextEdit').get(aem_ref)</code></pre>
59
-
60
-
61
- <p class="hilitebox">Note that the rb-aem documentation is not yet available; for now, refer to the py-aem documentation (rb-aem's API is virtually identical to py-aem's) and rb-aem source code for more information.</p>
62
-
63
-
64
-
65
- <h3>Use dump</h3>
66
-
67
- <p>Another way to deal with buggy or imcomplete application terminology is to export it as a Ruby module and correct it by hand. Appscript can then use the terminology data from this module instead of the broken terminology from the application itself.</p>
68
-
69
- <p>Exporting an application's terminology is done using the <code>dump.rb</code> script located in the <code>misc</code> folder. This script is designed to be run from the command line, and takes three arguments: the name or path of the application whose terminology you wish to export, followed by the new module's Ruby name and file path. For example:</p>
70
-
71
- <pre><code>ruby dump.rb iCal.app ICalTerminology ~/ical_terms.rb</code></pre>
72
-
73
- <p>The dump tool will generate a new Ruby module similar to the following:</p>
74
-
75
- <pre><code>module ICalTerminology
76
- Version = 1.1
77
- Path = "/Applications/iCal.app"
78
-
79
- Classes = [
80
- ["application", "capp"],
81
- ["attachment", "atts"],
82
- ["attendee", "wrea"],
83
- ...
84
- ]
85
-
86
- Enumerators = [
87
- ["accepted", "E6ap"],
88
- ["ask", "ask "],
89
- ...
90
- ]
91
-
92
- Properties = [
93
- ["allday_event", "wrad"],
94
- ["bounds", "pbnd"],
95
- ...
96
- ]
97
-
98
- Elements = [
99
- ["applications", "capp"],
100
- ["attachment", "atts"],
101
- ...
102
- ]
103
-
104
- Commands = [
105
- ["GetURL", "GURLGURL", [
106
- ]],
107
- ["close", "coreclos", [
108
- ["saving", "savo"],
109
- ["saving_in", "kfil"],
110
- ]],
111
- ...
112
- ]
113
- end</code></pre>
114
-
115
- <p>Every terminology module contains the following constants:</p>
116
-
117
- <dl>
118
- <dt>Version</dt>
119
- <dd>Indicates the terminology module's format. This is currently 1.1.</dd>
120
-
121
- <dt>Path</dt>
122
- <dd>The application from which this terminology was obtained.</dd>
123
-
124
- <dt>Classes</dt>
125
- <dd>A list of class names and their corresponding four-character codes as name-code pairs, e.g. <code>["document", "docu"]</code>.</dd>
126
-
127
- <dt>Enumerators</dt>
128
- <dd>A list of enumerator names and their corresponding four-character codes as name-code pairs, e.g. <code>["yes", "yes "]</code>.</dd>
129
-
130
- <dt>Properties</dt>
131
- <dd>A list of property names and their corresponding four-character codes as name-code pairs, e.g. <code>["name", "pnam"]</code>.</dd>
132
-
133
- <dt>Elements</dt>
134
- <dd>A list of element names and their corresponding four-character codes as name-code pairs, e.g. <code>["documents", "docu"]</code>. Note that this list should be identical to the <code>Classes</code> list, except that each element name should be the plural form of the corresponding class name.</dd>
135
-
136
- <dt>Commands</dt>
137
- <dd>A list of command names and their corresponding eight-character codes, followed by a list of keyword argument names and their corresponding four-character codes as name-code pairs, e.g. <code>["make", "corecrel", [["new", "kocl"],...]]</code>.</dd>
138
- </dl>
139
-
140
- <p>You can edit any of the five terminology lists as needed, e.g. to add missing class and element definitions, to correct faulty four-character codes, etc. (Make sure any changes are correctly formatted as appscript doesn't perform any special error checking when reading data from this module.) Once the changes are complete, place the module file somewhere on Ruby's module search path (e.g. in <code>/usr/lib/ruby/site_ruby/1.8</code>) so it can be imported into scripts when needed.</p>
141
-
142
- <p>To use a terminology module, first import it as normal. Then, when creating a new application object for the problem application, pass this module to the constructor call as its second argument (or first argument if it's the <code>current</code> constructor). For example:</p>
143
-
144
- <pre><code>require "appscript"
145
- require "ical_terms"
146
-
147
- ical = Appscript.app('iCal', ICalTerminology)
148
- ...</code></pre>
149
-
150
- <p>Finally, remember to file a bug report with the application's developer so that they can fix the problem in a future release!</p>
151
-
152
-
153
-
154
-
155
- <h2><a name="non_stay_open_applications">Scripting non-stay-open applications</h2>
156
-
157
- <p>When scripting AppleScript applets and other applications that take only a single <code>run</code> or <code>open</code> event, scripts must take some additional steps to avoid problems:<p>
158
-
159
- <ol>
160
- <li>When creating an application object, the <code>:terms</code> argument must be <code>false</code>. This will prevent appscript from repeatedly starting the application in an (unsuccessful) attempt to retrieve its terminology.</li>
161
-
162
- <li>When sending an <code>open</code> event, the application must first be started using the <code>launch</code> command to avoid it receiving the usual <code>run</code> event upon start-up.</li>
163
-
164
- <li>Since non-stay-open applications don't reply to commands, the <code>run</code>/<code>open</code> command's <code>:wait_reply</code> argument must be <code>false</code> to prevent appscript waiting for a non-existent response.</li>
165
- </ol>
166
-
167
- <p>Examples:</p>
168
-
169
- <pre><code>require "appscript"
170
-
171
- # Run
172
- Appscript.app('Foo', false).run(:wait_reply => false)
173
-
174
- # Open
175
- bar = Appscript.app('Bar', false)
176
- bar.launch
177
- bar.open([MacFile::Alias.path('/path/to/item 1'), ...], :wait_reply => false)</code></pre>
178
-
179
-
180
-
181
- </div>
182
-
183
- <!-- bottom navigation -->
184
- <div class="navbar">
185
- <a href="13_performanceissues.html">Previous</a> | <a href="index.html">Up</a> | <a href="15_notes.html">Next</a>
186
-
187
- </div>
188
-
189
- <!--footer-->
190
- <p class="footer">&copy; 2006 HAS</p>
191
- </body>
192
- </html>
@@ -1,14 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- # Copyright (C) 2006 HAS.
3
- # Released under MIT License.
4
-
5
- AdobeUnitTypes = [
6
- [:millimeters, "\x81MM\x8c"],
7
- [:points, "\x81PS\x8c"],
8
- [:picas, "\x81SP\x8c"],
9
- [:traditional_points, "\x81PT\x8c"],
10
- [:traditional_picas, "\x81PC\x8c"],
11
- [:ciceros, "\x81CR\x8c"],
12
- [:percent, "\x81PN\x8c"],
13
- [:pixels, "\x81PX\x8c"],
14
- ]
data/misc/dump.rb DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- # Copyright (C) 2006 HAS.
3
- # Released under MIT License.
4
-
5
- require "ae"
6
- require "aem"
7
- require "findapp"
8
- require "_appscript/terminology"
9
-
10
- if ARGV.length != 3
11
- puts "dump.rb
12
-
13
- Outputs an application's terminology as a Ruby module file, suitable for use by AS::Application.
14
-
15
- Usage:
16
-
17
- ruby dump.rb application-name-or-path module-name module-path
18
-
19
- Example:
20
-
21
- ruby dump.rb Address\ Book AddressBook ~/addressbook_terms.rb"
22
-
23
- exit
24
- end
25
-
26
- app_path = FindApp.by_name(ARGV[0])
27
- module_name = ARGV[1]
28
- out_path = ARGV[2]
29
-
30
- if not /^[A-Z][A-Za-z0-9_]*$/ === module_name
31
- raise RuntimeError, "Invalid module name."
32
- end
33
-
34
- File.open(out_path, "w") do |f|
35
- # Get aete(s)
36
- begin
37
- aetes = AEM::Codecs.new.unpack(AE.get_app_terminology(app_path).coerce(KAE::TypeAEList))
38
- rescue AE::MacOSError => e
39
- if e.to_i == -192 # aete resource not found
40
- raise RuntimeError, "No terminology found."
41
- else
42
- raise
43
- end
44
- end
45
-
46
- # Parse aete(s) into intermediate tables, suitable for use by Terminology#tables_for_module
47
- tables = TerminologyParser.build_tables_for_aetes(aetes)
48
-
49
- # Write module code
50
- f.puts "module #{module_name}"
51
- f.puts "\tVersion = 1.1"
52
- f.puts "\tPath = #{app_path.inspect}"
53
- f.puts
54
- (["Classes", "Enumerators", "Properties", "Elements"].zip(tables[0,4])).each do |name, table|
55
- f.puts "\t#{name} = ["
56
- table.sort.each do |item|
57
- f.puts "\t\t#{item.inspect},"
58
- end
59
- f.puts "\t]"
60
- f.puts
61
- end
62
- f.puts "\tCommands = ["
63
- tables[4].sort.each do |name, code, params|
64
- f.puts "\t\t[#{name.inspect}, #{code.inspect}, ["
65
- params.each do |item|
66
- f.puts "\t\t\t#{item.inspect},"
67
- end
68
- f.puts "\t\t]],"
69
- end
70
- f.puts "\t]"
71
- f.puts "end"
72
- end