rb-appscript 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CHANGES +243 -0
  2. data/LICENSE +1 -0
  3. data/README +42 -0
  4. data/TODO +31 -0
  5. data/doc/aem-manual/01_introduction.html +48 -0
  6. data/doc/aem-manual/02_apioverview.html +89 -0
  7. data/doc/aem-manual/03_packingandunpackingdata.html +98 -0
  8. data/doc/aem-manual/04_references.html +401 -0
  9. data/doc/aem-manual/05_targettingapplications.html +133 -0
  10. data/doc/aem-manual/06_buildingandsendingevents.html +175 -0
  11. data/doc/aem-manual/07_findapp.html +54 -0
  12. data/doc/aem-manual/08_examples.html +85 -0
  13. data/doc/aem-manual/09_notes.html +41 -0
  14. data/doc/aem-manual/aemreferenceinheritance.gif +0 -0
  15. data/doc/aem-manual/full.css +21 -0
  16. data/doc/aem-manual/index.html +43 -0
  17. data/doc/appscript-manual/01_introduction.html +82 -0
  18. data/doc/appscript-manual/02_aboutappscripting.html +244 -0
  19. data/doc/appscript-manual/03_quicktutorial.html +154 -0
  20. data/doc/appscript-manual/04_gettinghelp.html +101 -0
  21. data/doc/appscript-manual/05_keywordconversion.html +91 -0
  22. data/doc/appscript-manual/06_classesandenums.html +174 -0
  23. data/doc/appscript-manual/07_applicationobjects.html +181 -0
  24. data/doc/appscript-manual/08_realvsgenericreferences.html +86 -0
  25. data/doc/appscript-manual/09_referenceforms.html +232 -0
  26. data/doc/appscript-manual/10_referenceexamples.html +142 -0
  27. data/doc/appscript-manual/11_applicationcommands.html +204 -0
  28. data/doc/appscript-manual/12_commandexamples.html +129 -0
  29. data/doc/appscript-manual/13_performanceissues.html +115 -0
  30. data/doc/appscript-manual/14_problemapps.html +193 -0
  31. data/doc/appscript-manual/15_notes.html +84 -0
  32. data/doc/appscript-manual/application_architecture.gif +0 -0
  33. data/doc/appscript-manual/application_architecture2.gif +0 -0
  34. data/doc/appscript-manual/finder_to_textedit_event.gif +0 -0
  35. data/doc/appscript-manual/full.css +21 -0
  36. data/doc/appscript-manual/index.html +49 -0
  37. data/doc/appscript-manual/relationships_example.gif +0 -0
  38. data/doc/appscript-manual/ruby_to_itunes_event.gif +0 -0
  39. data/doc/index.html +30 -0
  40. data/doc/mactypes-manual/index.html +216 -0
  41. data/doc/osax-manual/index.html +169 -0
  42. data/extconf.rb +54 -0
  43. data/misc/adobeunittypes.rb +14 -0
  44. data/misc/dump.rb +72 -0
  45. data/rb-appscript.gemspec +20 -0
  46. data/sample/AB_list_people_with_emails.rb +8 -0
  47. data/sample/Create_daily_iCal_todos.rb +72 -0
  48. data/sample/Hello_world.rb +9 -0
  49. data/sample/List_iTunes_playlist_names.rb +7 -0
  50. data/sample/Make_Mail_message.rb +29 -0
  51. data/sample/Open_file_in_TextEdit.rb +9 -0
  52. data/sample/Organize_Mail_messages.rb +57 -0
  53. data/sample/Print_folder_tree.rb +12 -0
  54. data/sample/Select_all_HTML_files.rb +8 -0
  55. data/sample/Set_iChat_status.rb +20 -0
  56. data/sample/Simple_Finder_GUI_Scripting.rb +14 -0
  57. data/sample/Stagger_Finder_windows.rb +21 -0
  58. data/sample/TextEdit_demo.rb +126 -0
  59. data/sample/iTunes_top40_to_html.rb +64 -0
  60. data/src/lib/_aem/aemreference.rb +1006 -0
  61. data/src/lib/_aem/codecs.rb +617 -0
  62. data/src/lib/_aem/connect.rb +100 -0
  63. data/src/lib/_aem/findapp.rb +83 -0
  64. data/src/lib/_aem/mactypes.rb +228 -0
  65. data/src/lib/_aem/send.rb +257 -0
  66. data/src/lib/_aem/typewrappers.rb +57 -0
  67. data/src/lib/_appscript/defaultterminology.rb +245 -0
  68. data/src/lib/_appscript/referencerenderer.rb +132 -0
  69. data/src/lib/_appscript/reservedkeywords.rb +107 -0
  70. data/src/lib/_appscript/terminology.rb +314 -0
  71. data/src/lib/aem.rb +216 -0
  72. data/src/lib/appscript.rb +830 -0
  73. data/src/lib/kae.rb +1484 -0
  74. data/src/lib/osax.rb +171 -0
  75. data/src/rbae.c +766 -0
  76. data/test/README +1 -0
  77. data/test/test_aemreference.rb +112 -0
  78. data/test/test_appscriptreference.rb +102 -0
  79. data/test/test_codecs.rb +159 -0
  80. data/test/test_findapp.rb +24 -0
  81. data/test/test_mactypes.rb +67 -0
  82. data/test/testall.sh +9 -0
  83. metadata +143 -0
data/src/lib/osax.rb ADDED
@@ -0,0 +1,171 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require "appscript"
4
+
5
+ module OSAX
6
+
7
+ # Allows scripting additions (a.k.a. OSAXen) to be called from Ruby.
8
+
9
+ ######################################################################
10
+ # PRIVATE
11
+ ######################################################################
12
+
13
+ require "ae"
14
+ require "kae"
15
+ require "aem"
16
+
17
+ #######
18
+ # cache; stores osax paths and previously parsed terminology (if any) by osax name
19
+
20
+ OSAXCache = {}
21
+ OSAXNames = []
22
+
23
+ se = AS.app('System Events')
24
+ [se.system_domain, se.local_domain, se.user_domain].each do |domain|
25
+ osaxen = domain.scripting_additions_folder.files[
26
+ AS.its.file_type.eq('osax').or(AS.its.name_extension.eq('osax'))]
27
+ osaxen.name.get.zip(osaxen.POSIX_path.get).each do |name, path|
28
+ name = name.sub(/(?i)\.osax$/, '') # remove name extension, if any
29
+ OSAXNames.push(name)
30
+ OSAXCache[name.downcase] = [path, nil]
31
+ end
32
+ end
33
+ OSAXNames.sort.uniq
34
+
35
+ #######
36
+ # modified AppData class
37
+
38
+ class OSAXData < AS::AppData
39
+
40
+ def initialize(name, pid, url, terms)
41
+ super(AEM::Application, name, pid, url, terms)
42
+ end
43
+
44
+ def _connect
45
+ if @path
46
+ @target = @_aem_application_class.by_path(@path)
47
+ elsif @pid
48
+ @target = @_aem_application_class.by_pid(@pid)
49
+ elsif @url
50
+ @target = @_aem_application_class.by_url(@url)
51
+ else
52
+ @target = @_aem_application_class.current
53
+ end
54
+ begin
55
+ @target.event('ascrgdut').send(300) # make sure target application has loaded event handlers for all installed OSAXen
56
+ rescue AEM::CommandError => e
57
+ if e.number != -1708 # ignore 'event not handled' error
58
+ raise
59
+ end
60
+ end
61
+ @type_by_code, @type_by_name, @reference_by_code, @reference_by_name = @_terms
62
+ extend(AS::AppDataAccessors)
63
+ end
64
+
65
+ end
66
+
67
+
68
+ ######################################################################
69
+ # PUBLIC
70
+ ######################################################################
71
+
72
+ def OSAX.scripting_additions
73
+ # list names of all currently installed scripting additions
74
+ return OSAXNames
75
+ end
76
+
77
+ def OSAX.osax(name, app_name=nil)
78
+ # convenience method; provides shortcut for creating a new ScriptingAddition instance;
79
+ # a target application's name or full path may optionally be given as well
80
+ addition = ScriptingAddition.new(name)
81
+ if app_name
82
+ addition = addition.by_name(app_name)
83
+ end
84
+ return addition
85
+ end
86
+
87
+
88
+ class ScriptingAddition < AS::Reference
89
+ # Represents a single scripting addition.
90
+
91
+ def initialize(name)
92
+ # name: string -- a scripting addition's name, e.g. "StandardAdditions";
93
+ # basically its filename minus the '.osax' suffix
94
+ #
95
+ # Note that name is case-insensitive and an '.osax' suffix is ignored if given.
96
+ @_osax_name = name
97
+ if name.is_a?(OSAXData)
98
+ osax_data = name
99
+ else
100
+ path, terms = OSAXCache[name.downcase.sub(/(?i)\.osax$/, '')]
101
+ if not path
102
+ raise ArgumentError, "Scripting addition not found: #{name.inspect}"
103
+ end
104
+ if terms
105
+ @_terms = terms
106
+ else
107
+ desc = AE.get_app_terminology(path).coerce(KAE::TypeAEList)
108
+ @_terms = OSAXCache[name.downcase][1] = \
109
+ Terminology.tables_for_aetes(DefaultCodecs.unpack(desc))
110
+ end
111
+ osax_data = OSAXData.new(nil, nil, nil, @_terms)
112
+ end
113
+ super(osax_data, AEM.app)
114
+ end
115
+
116
+ def to_s
117
+ return "#<OSAX::ScriptingAddition name=#{@_osax_name.inspect} target=#{@AS_app_data.target.inspect}>"
118
+ end
119
+
120
+ alias_method :inspect, :to_s
121
+
122
+ ##
123
+
124
+ def method_missing(name, *args)
125
+ begin
126
+ super
127
+ rescue AS::CommandError => e
128
+ if e.to_i == -1713 # 'No user interaction allowed' error (e.g. user tried to send a 'display dialog' command to a non-GUI ruby process), so convert the target process to a full GUI process and try again
129
+ AE.transform_process_to_foreground_application
130
+ activate
131
+ super
132
+ else
133
+ raise
134
+ end
135
+ end
136
+ end
137
+
138
+ # A client-created scripting addition is automatically targetted at the current application.
139
+ # Clients can specify another application as target by calling one of the following methods:
140
+
141
+ def by_name(name)
142
+ # name : string -- name or full path to application
143
+ return ScriptingAddition.new(OSAXData.new(FindApp.by_name(name), nil, nil, @_terms))
144
+ end
145
+
146
+ def by_id(id)
147
+ # id : string -- bundle id of application
148
+ return ScriptingAddition.new(OSAXData.new(FindApp.by_id(id), nil, nil, @_terms))
149
+ end
150
+
151
+ def by_creator(creator)
152
+ # creator : string -- four-character creator code of application
153
+ return ScriptingAddition.new(OSAXData.new(FindApp.by_creator(creator), nil, nil, @_terms))
154
+ end
155
+
156
+ def by_pid(pid)
157
+ # pid : integer -- Unix process id
158
+ return ScriptingAddition.new(OSAXData.new(nil, pid, nil, @_terms))
159
+ end
160
+
161
+ def by_url(url)
162
+ # url : string -- eppc URL of application
163
+ return ScriptingAddition.new(OSAXData.new(nil, nil, url, @_terms))
164
+ end
165
+
166
+ def current
167
+ return ScriptingAddition.new(OSAXData.new(nil, nil, nil, @_terms))
168
+ end
169
+ end
170
+
171
+ end