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
@@ -5,81 +5,81 @@
5
5
  #
6
6
 
7
7
  module FindApp
8
- # Support module for obtaining the full path to a local application given its name, bundle id or creator type. If application isn't found, an ApplicationNotFoundError exception is raised.
8
+ # Support module for obtaining the full path to a local application given its name, bundle id or creator type. If application isn't found, an ApplicationNotFoundError exception is raised.
9
9
 
10
- require "ae"
11
-
12
- class ApplicationNotFoundError < RuntimeError
13
-
14
- attr_reader :creator_type, :bundle_id, :application_name
15
-
16
- def initialize(creator, id, name)
17
- @creator_type, @bundle_id, @application_name = creator, id, name
18
- super()
19
- end
20
- end
21
-
22
- #######
23
-
24
- def FindApp._find_app(creator, id, name)
25
- begin
26
- return AE.find_application(creator, id, name)
27
- rescue AE::MacOSError => err
28
- if err.to_i == -10814
29
- ident = [creator, id, name].compact.to_s.inspect
30
- raise ApplicationNotFoundError.new(creator, id, name), "Application #{ident} not found."
31
- else
32
- raise
33
- end
34
- end
35
- end
36
-
37
- #######
10
+ require "ae"
38
11
 
39
- def FindApp.by_name(name)
40
- # Find the application with the given name and return its full path.
41
- #
42
- # Absolute paths are also accepted. An '.app' suffix is optional.
43
- #
44
- # Examples:
45
- # FindApp.by_name('TextEdit')
46
- # FindApp.by_name('Finder.app')
47
- #
48
- if name[0, 1] != '/' # application name only, not its full path
49
- begin
50
- new_name = _find_app(nil, nil, name)
51
- rescue ApplicationNotFoundError
52
- if ('----' + name)[-4, 4].downcase == '.app'
53
- raise ApplicationNotFoundError.new(nil, nil, name), "Application #{name.inspect} not found."
54
- end
55
- new_name = _find_app(nil, nil, name + '.app')
56
- end
57
- name = new_name
58
- end
59
- if not FileTest.exist?(name) and name[-4, 4].downcase != '.app' and not FileTest.exist?(name+ '.app')
60
- name += '.app'
61
- end
62
- if not FileTest.exist?(name)
63
- raise ApplicationNotFoundError.new(nil, nil, name), "Application #{name.inspect} not found."
64
- end
65
- return name
66
- end
67
-
68
- def FindApp.by_id(id)
69
- # Find the application with the given bundle id and return its full path.
70
- #
71
- # Examples:
72
- # FindApp.by_id('com.apple.textedit')
73
- #
74
- return _find_app(nil, id, nil)
75
- end
76
-
77
- def FindApp.by_creator(creator)
78
- # Find the application with the given creator type and return its full path.
79
- #
80
- # Examples:
81
- # FindApp.by_creator('ttxt')
82
- #
83
- return _find_app(creator, nil, nil)
84
- end
12
+ class ApplicationNotFoundError < RuntimeError
13
+
14
+ attr_reader :creator_type, :bundle_id, :application_name
15
+
16
+ def initialize(creator, id, name)
17
+ @creator_type, @bundle_id, @application_name = creator, id, name
18
+ super()
19
+ end
20
+ end
21
+
22
+ #######
23
+
24
+ def FindApp._find_app(creator, id, name)
25
+ begin
26
+ return AE.find_application(creator, id, name)
27
+ rescue AE::MacOSError => err
28
+ if err.to_i == -10814
29
+ ident = [creator, id, name].compact.to_s.inspect
30
+ raise ApplicationNotFoundError.new(creator, id, name), "Application #{ident} not found."
31
+ else
32
+ raise
33
+ end
34
+ end
35
+ end
36
+
37
+ #######
38
+
39
+ def FindApp.by_name(name)
40
+ # Find the application with the given name and return its full path.
41
+ #
42
+ # Absolute paths are also accepted. An '.app' suffix is optional.
43
+ #
44
+ # Examples:
45
+ # FindApp.by_name('TextEdit')
46
+ # FindApp.by_name('Finder.app')
47
+ #
48
+ if name[0, 1] != '/' # application name only, not its full path
49
+ begin
50
+ new_name = _find_app(nil, nil, name)
51
+ rescue ApplicationNotFoundError
52
+ if ('----' + name)[-4, 4].downcase == '.app'
53
+ raise ApplicationNotFoundError.new(nil, nil, name), "Application #{name.inspect} not found."
54
+ end
55
+ new_name = _find_app(nil, nil, name + '.app')
56
+ end
57
+ name = new_name
58
+ end
59
+ if not FileTest.exist?(name) and name[-4, 4].downcase != '.app' and not FileTest.exist?(name+ '.app')
60
+ name += '.app'
61
+ end
62
+ if not FileTest.exist?(name)
63
+ raise ApplicationNotFoundError.new(nil, nil, name), "Application #{name.inspect} not found."
64
+ end
65
+ return name
66
+ end
67
+
68
+ def FindApp.by_id(id)
69
+ # Find the application with the given bundle id and return its full path.
70
+ #
71
+ # Examples:
72
+ # FindApp.by_id('com.apple.textedit')
73
+ #
74
+ return _find_app(nil, id, nil)
75
+ end
76
+
77
+ def FindApp.by_creator(creator)
78
+ # Find the application with the given creator type and return its full path.
79
+ #
80
+ # Examples:
81
+ # FindApp.by_creator('ttxt')
82
+ #
83
+ return _find_app(creator, nil, nil)
84
+ end
85
85
  end
@@ -5,247 +5,246 @@
5
5
  #
6
6
 
7
7
  module MacTypes
8
- # Defines wrapper classes for Mac OS datatypes that don't have a suitable Ruby equivalent.
9
- #
10
- # Note: all path strings are/must be valid UTF8.
11
-
12
- require "ae"
13
- require "kae"
14
-
15
- KCFURLPOSIXPathStyle = 0
16
- KCFURLHFSPathStyle = 1
17
- KCFURLWindowsPathStyle = 2
18
-
19
- class FileBase
20
-
21
- def FileBase._coerce(desc, type, path=nil)
22
- begin
23
- return desc.coerce(type)
24
- rescue AE::MacOSError => e
25
- if [-35, -43, -120, -1700].include?(e.to_i) # disk/file/folder not found, or coercion error
26
- if path != nil
27
- raise FileNotFoundError, "File #{path.inspect} not found."
28
- else
29
- raise FileNotFoundError, "File not found."
30
- end
31
- else
32
- raise
33
- end
34
- end
35
- end
36
-
37
- def ==(val)
38
- return (self.equal?(val) or (self.class == val.class and self.url == val.url))
39
- end
40
-
41
- alias_method :eql?, :==
42
-
43
- def hash
44
- return [desc.type, desc.data].hash
45
- end
46
- end
47
-
48
- # public
49
-
50
- class Alias < FileBase
51
- # Wraps AEDescs of typeAlias. Alias objects keep track of filesystem objects as they're moved around the disk or renamed.
52
- #
53
- # Since Ruby doesn't already bridge the Mac OS's Alias Manager, simplest solution is to always store data internally as an AEDesc of typeAlias, and convert this to other forms on demand (e.g. when casting to string).
54
-
55
- private_class_method :new
56
-
57
- def initialize(desc)
58
- @desc = desc
59
- end
60
-
61
- # Constructors
62
-
63
- def Alias.path(path)
64
- # Make Alias object from POSIX path.
65
- return new(FileBase._coerce(
66
- AE::AEDesc.new(KAE::TypeFileURL, AE.convert_path_to_url(path, KCFURLPOSIXPathStyle)),
67
- KAE::TypeAlias, path))
68
- end
69
-
70
- def Alias.hfs_path(path)
71
- # Make Alias object from HFS path.
72
- return new(FileBase._coerce(
73
- AE::AEDesc.new(KAE::TypeFileURL, AE.convert_path_to_url(path, KCFURLHFSPathStyle)),
74
- KAE::TypeAlias, path))
75
- end
76
-
77
- def Alias.url(url)
78
- # Make Alias object from file URL. Note: only the path portion of the URL is used; the domain will always be localhost.
79
- return Alias.path(AE.convert_url_to_path(url, KCFURLPOSIXPathStyle))
80
- end
81
-
82
- def Alias.desc(desc)
83
- # Make Alias object from CarbonX.AE.AEDesc of typeAlias. Note: descriptor type is not checked; clients are responsible for passing the correct type as other types will cause unexpected problems/errors.
84
- return new(desc)
85
- end
86
-
87
- # Methods
88
-
89
- attr_reader :desc # Return AEDesc of typeAlias. If clients want a different type, they can subsequently call this AEDesc's coerce method.
90
-
91
- def url
92
- # Get as URL string.
93
- return desc.coerce(KAE::TypeFileURL).data
94
- end
95
-
96
- def path
97
- # Get as POSIX path.
98
- return AE.convert_url_to_path(FileBase._coerce(@desc, KAE::TypeFileURL).data, KCFURLPOSIXPathStyle)
99
- end
100
-
101
- def hfs_path
102
- # Get as HFS path.
103
- return AE.convert_url_to_path(FileBase._coerce(@desc, KAE::TypeFileURL).data, KCFURLHFSPathStyle)
104
- end
105
-
106
- alias_method :to_s, :path
107
-
108
- def inspect
109
- return "MacTypes::Alias.path(#{to_s.inspect})"
110
- end
111
-
112
- def to_alias
113
- # Get as MacTypes::Alias.
114
- return self
115
- end
116
-
117
- def to_file_url
118
- # Get as MacTypes::FileURL; note that the resulting FileURL object will always pack as an AEDesc of typeFileURL.
119
- return MacTypes::FileURL.desc(FileBase._coerce(@desc, KAE::TypeFileURL))
120
- end
121
- end
122
-
123
- ##
124
-
125
- class FileURL < FileBase
126
- # Wraps AEDescs of typeFSRef/typeFSS/typeFileURL to save user from having to deal with them directly. FileURL objects refer to specific locations on the filesystem which may or may not already exist.
127
-
128
- private_class_method :new
129
-
130
- def initialize(path, desc)
131
- @path = path
132
- @desc = desc
133
- end
134
-
135
- # Constructors
136
-
137
- def FileURL.path(path)
138
- # Make FileURL object from POSIX path.
139
- return new(path, nil)
140
- end
141
-
142
- def FileURL.hfs_path(path)
143
- # Make FileURL object from HFS path.
144
- return new(AE.convert_url_to_path(AE.convert_path_to_url(path, KCFURLHFSPathStyle), KCFURLPOSIXPathStyle), nil)
145
- end
146
-
147
- def FileURL.url(url)
148
- # Make FileURL object from file URL. Note: only the path portion of the URL is used; the domain will always be localhost.
149
- return FileURL.path(AE.convert_url_to_path(url, KCFURLPOSIXPathStyle))
150
- end
151
-
152
- def FileURL.desc(desc)
153
- # Make FileURL object from AEDesc of typeFSS, typeFSRef, typeFileURL. Note: descriptor type is not checked; clients are responsible for passing the correct type as other types will cause unexpected problems/errors.
154
- return new(nil, desc)
155
- end
156
-
157
- # Methods
158
-
159
- def desc
160
- # Get as AEDesc. If constructed from Ruby, descriptor's type is always typeFileURL; if returned by aem, its type may be typeFSS, typeFSRef or typeFileURL.
161
- if not @desc
162
- @desc = AE::AEDesc.new(KAE::TypeFileURL, AE.convert_path_to_url(@path, KCFURLPOSIXPathStyle))
163
- end
164
- return @desc
165
- end
166
-
167
- def url
168
- # Get as URL string.
169
- return desc.coerce(KAE::TypeFileURL).data
170
- end
171
-
172
- def path
173
- # Get as POSIX path.
174
- if not @path
175
- @path = AE.convert_url_to_path(FileBase._coerce(@desc, KAE::TypeFileURL).data, KCFURLPOSIXPathStyle)
176
- end
177
- return @path
178
- end
179
-
180
- def hfs_path
181
- return AE.convert_url_to_path(AE.convert_path_to_url(path, KCFURLPOSIXPathStyle), KCFURLHFSPathStyle)
182
- end
183
-
184
- alias_method :to_s, :path
185
-
186
- def inspect
187
- return "MacTypes::FileURL.path(#{to_s.inspect})"
188
- end
189
-
190
- def to_alias
191
- # Get as MacTypes::Alias.
192
- return MacTypes::Alias.desc(FileBase._coerce(desc, KAE::TypeAlias, to_s))
193
- end
194
-
195
- def to_file_url
196
- # Get as MacTypes::FileURL; note that the resulting FileURL object will always pack as an AEDesc of typeFileURL.
197
- return MacTypes::FileURL.desc(FileBase._coerce(desc, KAE::TypeFileURL, to_s))
198
- end
199
- end
200
-
201
- ##
202
-
203
- class FileNotFoundError < RuntimeError
204
- # Raised when an operation that only works for an existing filesystem object/location is performed on an Alias/FileURL object that identifies a non-existent object/location.
205
- end
206
-
207
- #######
208
-
209
- class Units
210
- # Represents a measurement; e.g. 3 inches, 98.5 degrees Fahrenheit.
211
- #
212
- # The AEM defines a standard set of unit types; some applications may define additional types for their own use. This wrapper stores the raw unit type and value data; aem/appscript Codecs objects will convert this to/from an AEDesc, or raise an error if the unit type is unrecognised.
213
-
214
- attr_reader :value, :type
215
-
216
- def initialize(value, type)
217
- @value = value
218
- @type = type
219
- end
220
-
221
- def ==(val)
222
- return (self.equal?(val) or (
223
- self.class == val.class and
224
- @value == val.value and @type == val.type))
225
- end
226
-
227
- alias_method :eql?, :==
228
-
229
- def hash
230
- return [@value, @type].hash
231
- end
232
-
233
- def to_i
234
- return @value.to_i
235
- end
236
-
237
- def to_f
238
- return @value.to_f
239
- end
240
-
241
- def to_s
242
- return "#{@value.inspect} #{@type.tr('_', ' ')}"
243
- end
244
-
245
- def inspect
246
- return "MacTypes::Units.new(#{@value.inspect}, #{@type.inspect})"
247
- end
248
- end
8
+ # Defines wrapper classes for Mac OS datatypes that don't have a suitable Ruby equivalent.
9
+ #
10
+ # Note: all path strings are/must be valid UTF8.
249
11
 
250
- end
12
+ require "ae"
13
+ require "kae"
14
+
15
+ KCFURLPOSIXPathStyle = 0
16
+ KCFURLHFSPathStyle = 1
17
+ KCFURLWindowsPathStyle = 2
18
+
19
+ class FileBase
20
+
21
+ def FileBase._coerce(desc, type, path=nil)
22
+ begin
23
+ return desc.coerce(type)
24
+ rescue AE::MacOSError => e
25
+ if [-35, -43, -120, -1700].include?(e.to_i) # disk/file/folder not found, or coercion error
26
+ if path != nil
27
+ raise FileNotFoundError, "File #{path.inspect} not found."
28
+ else
29
+ raise FileNotFoundError, "File not found."
30
+ end
31
+ else
32
+ raise
33
+ end
34
+ end
35
+ end
36
+
37
+ def ==(val)
38
+ return (self.equal?(val) or (self.class == val.class and self.url == val.url))
39
+ end
40
+
41
+ alias_method :eql?, :==
42
+
43
+ def hash
44
+ return [desc.type, desc.data].hash
45
+ end
46
+ end
47
+
48
+ # public
49
+
50
+ class Alias < FileBase
51
+ # Wraps AEDescs of typeAlias. Alias objects keep track of filesystem objects as they're moved around the disk or renamed.
52
+ #
53
+ # Since Ruby doesn't already bridge the Mac OS's Alias Manager, simplest solution is to always store data internally as an AEDesc of typeAlias, and convert this to other forms on demand (e.g. when casting to string).
54
+
55
+ private_class_method :new
56
+
57
+ def initialize(desc)
58
+ @desc = desc
59
+ end
60
+
61
+ # Constructors
62
+
63
+ def Alias.path(path)
64
+ # Make Alias object from POSIX path.
65
+ return new(FileBase._coerce(
66
+ AE::AEDesc.new(KAE::TypeFileURL, AE.convert_path_to_url(path, KCFURLPOSIXPathStyle)),
67
+ KAE::TypeAlias, path))
68
+ end
69
+
70
+ def Alias.hfs_path(path)
71
+ # Make Alias object from HFS path.
72
+ return new(FileBase._coerce(
73
+ AE::AEDesc.new(KAE::TypeFileURL, AE.convert_path_to_url(path, KCFURLHFSPathStyle)),
74
+ KAE::TypeAlias, path))
75
+ end
76
+
77
+ def Alias.url(url)
78
+ # Make Alias object from file URL. Note: only the path portion of the URL is used; the domain will always be localhost.
79
+ return Alias.path(AE.convert_url_to_path(url, KCFURLPOSIXPathStyle))
80
+ end
81
+
82
+ def Alias.desc(desc)
83
+ # Make Alias object from CarbonX.AE.AEDesc of typeAlias. Note: descriptor type is not checked; clients are responsible for passing the correct type as other types will cause unexpected problems/errors.
84
+ return new(desc)
85
+ end
86
+
87
+ # Methods
88
+
89
+ attr_reader :desc # Return AEDesc of typeAlias. If clients want a different type, they can subsequently call this AEDesc's coerce method.
90
+
91
+ def url
92
+ # Get as URL string.
93
+ return desc.coerce(KAE::TypeFileURL).data
94
+ end
95
+
96
+ def path
97
+ # Get as POSIX path.
98
+ return AE.convert_url_to_path(FileBase._coerce(@desc, KAE::TypeFileURL).data, KCFURLPOSIXPathStyle)
99
+ end
100
+
101
+ def hfs_path
102
+ # Get as HFS path.
103
+ return AE.convert_url_to_path(FileBase._coerce(@desc, KAE::TypeFileURL).data, KCFURLHFSPathStyle)
104
+ end
105
+
106
+ alias_method :to_s, :path
107
+
108
+ def inspect
109
+ return "MacTypes::Alias.path(#{to_s.inspect})"
110
+ end
111
+
112
+ def to_alias
113
+ # Get as MacTypes::Alias.
114
+ return self
115
+ end
116
+
117
+ def to_file_url
118
+ # Get as MacTypes::FileURL; note that the resulting FileURL object will always pack as an AEDesc of typeFileURL.
119
+ return MacTypes::FileURL.desc(FileBase._coerce(@desc, KAE::TypeFileURL))
120
+ end
121
+ end
122
+
123
+ ##
124
+
125
+ class FileURL < FileBase
126
+ # Wraps AEDescs of typeFSRef/typeFSS/typeFileURL to save user from having to deal with them directly. FileURL objects refer to specific locations on the filesystem which may or may not already exist.
127
+
128
+ private_class_method :new
129
+
130
+ def initialize(path, desc)
131
+ @path = path
132
+ @desc = desc
133
+ end
251
134
 
135
+ # Constructors
136
+
137
+ def FileURL.path(path)
138
+ # Make FileURL object from POSIX path.
139
+ return new(path, nil)
140
+ end
141
+
142
+ def FileURL.hfs_path(path)
143
+ # Make FileURL object from HFS path.
144
+ return new(AE.convert_url_to_path(AE.convert_path_to_url(path, KCFURLHFSPathStyle), KCFURLPOSIXPathStyle), nil)
145
+ end
146
+
147
+ def FileURL.url(url)
148
+ # Make FileURL object from file URL. Note: only the path portion of the URL is used; the domain will always be localhost.
149
+ return FileURL.path(AE.convert_url_to_path(url, KCFURLPOSIXPathStyle))
150
+ end
151
+
152
+ def FileURL.desc(desc)
153
+ # Make FileURL object from AEDesc of typeFSS, typeFSRef, typeFileURL. Note: descriptor type is not checked; clients are responsible for passing the correct type as other types will cause unexpected problems/errors.
154
+ return new(nil, desc)
155
+ end
156
+
157
+ # Methods
158
+
159
+ def desc
160
+ # Get as AEDesc. If constructed from Ruby, descriptor's type is always typeFileURL; if returned by aem, its type may be typeFSS, typeFSRef or typeFileURL.
161
+ if not @desc
162
+ @desc = AE::AEDesc.new(KAE::TypeFileURL, AE.convert_path_to_url(@path, KCFURLPOSIXPathStyle))
163
+ end
164
+ return @desc
165
+ end
166
+
167
+ def url
168
+ # Get as URL string.
169
+ return desc.coerce(KAE::TypeFileURL).data
170
+ end
171
+
172
+ def path
173
+ # Get as POSIX path.
174
+ if not @path
175
+ @path = AE.convert_url_to_path(FileBase._coerce(@desc, KAE::TypeFileURL).data, KCFURLPOSIXPathStyle)
176
+ end
177
+ return @path
178
+ end
179
+
180
+ def hfs_path
181
+ return AE.convert_url_to_path(AE.convert_path_to_url(path, KCFURLPOSIXPathStyle), KCFURLHFSPathStyle)
182
+ end
183
+
184
+ alias_method :to_s, :path
185
+
186
+ def inspect
187
+ return "MacTypes::FileURL.path(#{to_s.inspect})"
188
+ end
189
+
190
+ def to_alias
191
+ # Get as MacTypes::Alias.
192
+ return MacTypes::Alias.desc(FileBase._coerce(desc, KAE::TypeAlias, to_s))
193
+ end
194
+
195
+ def to_file_url
196
+ # Get as MacTypes::FileURL; note that the resulting FileURL object will always pack as an AEDesc of typeFileURL.
197
+ return MacTypes::FileURL.desc(FileBase._coerce(desc, KAE::TypeFileURL, to_s))
198
+ end
199
+ end
200
+
201
+ ##
202
+
203
+ class FileNotFoundError < RuntimeError
204
+ # Raised when an operation that only works for an existing filesystem object/location is performed on an Alias/FileURL object that identifies a non-existent object/location.
205
+ end
206
+
207
+ #######
208
+
209
+ class Units
210
+ # Represents a measurement; e.g. 3 inches, 98.5 degrees Fahrenheit.
211
+ #
212
+ # The AEM defines a standard set of unit types; some applications may define additional types for their own use. This wrapper stores the raw unit type and value data; aem/appscript Codecs objects will convert this to/from an AEDesc, or raise an error if the unit type is unrecognised.
213
+
214
+ attr_reader :value, :type
215
+
216
+ def initialize(value, type)
217
+ @value = value
218
+ @type = type
219
+ end
220
+
221
+ def ==(val)
222
+ return (self.equal?(val) or (
223
+ self.class == val.class and
224
+ @value == val.value and @type == val.type))
225
+ end
226
+
227
+ alias_method :eql?, :==
228
+
229
+ def hash
230
+ return [@value, @type].hash
231
+ end
232
+
233
+ def to_i
234
+ return @value.to_i
235
+ end
236
+
237
+ def to_f
238
+ return @value.to_f
239
+ end
240
+
241
+ def to_s
242
+ return "#{@value.inspect} #{@type.tr('_', ' ')}"
243
+ end
244
+
245
+ def inspect
246
+ return "MacTypes::Units.new(#{@value.inspect}, #{@type.inspect})"
247
+ end
248
+ end
249
+
250
+ end