Module: OSAX
- Defined in:
- lib/osax.rb
Defined Under Namespace
Classes: OSAXData, ScriptingAddition, SdefParser
Constant Summary collapse
- StandardAdditionsEnums =
[ ["stop", "\000\000\000\000"], ["note", "\000\000\000\001"], ["caution", "\000\000\000\002"]]
- UTF8ToMacRoman =
{ 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 16 => 16, 17 => 17, 18 => 18, 19 => 19, 20 => 20, 21 => 21, 22 => 22, 23 => 23, 24 => 24, 25 => 25, 26 => 26, 27 => 27, 28 => 28, 29 => 29, 30 => 30, 31 => 31, 32 => 32, 33 => 33, 34 => 34, 35 => 35, 36 => 36, 37 => 37, 38 => 38, 39 => 39, 40 => 40, 41 => 41, 42 => 42, 43 => 43, 44 => 44, 45 => 45, 46 => 46, 47 => 47, 48 => 48, 49 => 49, 50 => 50, 51 => 51, 52 => 52, 53 => 53, 54 => 54, 55 => 55, 56 => 56, 57 => 57, 58 => 58, 59 => 59, 60 => 60, 61 => 61, 62 => 62, 63 => 63, 64 => 64, 65 => 65, 66 => 66, 67 => 67, 68 => 68, 69 => 69, 70 => 70, 71 => 71, 72 => 72, 73 => 73, 74 => 74, 75 => 75, 76 => 76, 77 => 77, 78 => 78, 79 => 79, 80 => 80, 81 => 81, 82 => 82, 83 => 83, 84 => 84, 85 => 85, 86 => 86, 87 => 87, 88 => 88, 89 => 89, 90 => 90, 91 => 91, 92 => 92, 93 => 93, 94 => 94, 95 => 95, 96 => 96, 97 => 97, 98 => 98, 99 => 99, 100 => 100, 101 => 101, 102 => 102, 103 => 103, 104 => 104, 105 => 105, 106 => 106, 107 => 107, 108 => 108, 109 => 109, 110 => 110, 111 => 111, 112 => 112, 113 => 113, 114 => 114, 115 => 115, 116 => 116, 117 => 117, 118 => 118, 119 => 119, 120 => 120, 121 => 121, 122 => 122, 123 => 123, 124 => 124, 125 => 125, 126 => 126, 127 => 127, 196 => 128, 197 => 129, 199 => 130, 201 => 131, 209 => 132, 214 => 133, 220 => 134, 225 => 135, 224 => 136, 226 => 137, 228 => 138, 227 => 139, 229 => 140, 231 => 141, 233 => 142, 232 => 143, 234 => 144, 235 => 145, 237 => 146, 236 => 147, 238 => 148, 239 => 149, 241 => 150, 243 => 151, 242 => 152, 244 => 153, 246 => 154, 245 => 155, 250 => 156, 249 => 157, 251 => 158, 252 => 159, 8224 => 160, 176 => 161, 162 => 162, 163 => 163, 167 => 164, 8226 => 165, 182 => 166, 223 => 167, 174 => 168, 169 => 169, 8482 => 170, 180 => 171, 168 => 172, 8800 => 173, 198 => 174, 216 => 175, 8734 => 176, 177 => 177, 8804 => 178, 8805 => 179, 165 => 180, 181 => 181, 8706 => 182, 8721 => 183, 8719 => 184, 960 => 185, 8747 => 186, 170 => 187, 186 => 188, 937 => 189, 230 => 190, 248 => 191, 191 => 192, 161 => 193, 172 => 194, 8730 => 195, 402 => 196, 8776 => 197, 8710 => 198, 171 => 199, 187 => 200, 8230 => 201, 160 => 202, 192 => 203, 195 => 204, 213 => 205, 338 => 206, 339 => 207, 8211 => 208, 8212 => 209, 8220 => 210, 8221 => 211, 8216 => 212, 8217 => 213, 247 => 214, 9674 => 215, 255 => 216, 376 => 217, 8260 => 218, 8364 => 219, 8249 => 220, 8250 => 221, 64257 => 222, 64258 => 223, 8225 => 224, 183 => 225, 8218 => 226, 8222 => 227, 8240 => 228, 194 => 229, 202 => 230, 193 => 231, 203 => 232, 200 => 233, 205 => 234, 206 => 235, 207 => 236, 204 => 237, 211 => 238, 212 => 239, 63743 => 240, 210 => 241, 218 => 242, 219 => 243, 217 => 244, 305 => 245, 710 => 246, 732 => 247, 175 => 248, 728 => 249, 729 => 250, 730 => 251, 184 => 252, 733 => 253, 731 => 254, 711 => 255}
- OSAXCache =
cache; stores osax paths and previously parsed terminology (if any) by osax name
{}
- OSAXNames =
[]
Class Method Summary collapse
- ._init_caches ⇒ Object
- .dump(osax_name, module_name, out_path) ⇒ Object
- .osax(name = nil, app_name = nil) ⇒ Object
-
.scripting_additions ⇒ Object
PUBLIC.
Instance Method Summary collapse
- #osax(*args) ⇒ Object
-
#scripting_additions ⇒ Object
allow methods to be included via ‘include OSAX’.
Class Method Details
._init_caches ⇒ Object
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/osax.rb', line 442 def OSAX._init_caches se = AEM::Application.by_path(FindApp.by_id('com.apple.systemevents')) ['flds', 'fldl', 'fldu'].each do |domain_code| osaxen = AEM.app.property(domain_code).property('$scr').elements('file').by_filter( AEM.its.property('asty').eq('osax').or(AEM.its.property('extn').eq('osax'))) if se.event('coredoex', {'----' => osaxen.property('pnam')}).send # domain has ScriptingAdditions folder names = se.event('coregetd', {'----' => osaxen.property('pnam')}).send paths = se.event('coregetd', {'----' => osaxen.property('posx')}).send names.zip(paths).each do |name, path| name = name.sub(/(?i)\.osax$/, '') # remove name extension, if any OSAXNames.push(name) OSAXCache[name.downcase] = [path, nil] end end end OSAXNames.sort!.uniq! end |
.dump(osax_name, module_name, out_path) ⇒ Object
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/osax.rb', line 624 def OSAX.dump(osax_name, module_name, out_path) # Export scripting addition terminology tables as a Ruby module # osaxname : string -- name of installed scripting addition # module_name : string -- name of generated module (must be a valid Ruby constant) # out_path : string -- module file to write # # Generates a Ruby module containing a scripting addition's basic terminology # (names and codes). # # Call the #dump method to dump faulty sdefs to Ruby module, e.g.: # # dump('MyOSAX', 'MyOSAXGlue', '/path/to/site-packages/myosaxglue.py') # # Patch any errors by hand, then import the patched module into your script # and pass it to OSAX.osax via its 'terms' argument, e.g.: # # require 'osax' # require 'MyOSAXGlue' # # myapp = OSAX.osax('MyOSAX', terms => MyOSAXGlue) # OSAX._init_caches if OSAXNames == [] original_name = osax_name osax_name = osax_name.downcase m = /^(.+).osax$/.match(osax_name) osax_name = m[1] if m != nil osax_path, _terms = OSAXCache.fetch(osax_name) do raise ArgumentError, "Scripting addition not found: #{original_name.inspect}" end sp = OSAX::SdefParser.new sp.parsefile(osax_path) Terminology.dump_tables([sp.classes, sp.enumerators, sp.properties, sp.elements, sp.commands], module_name, osax_path, out_path) end |
.osax(name = nil, app_name = nil) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/osax.rb', line 470 def OSAX.osax(name=nil, app_name=nil) # Convenience method for creating a new ScriptingAddition instance. # name : String | nil -- scripting addition's name; nil = 'StandardAdditions' # app_name : String | nil -- target application's name/path, or nil for current application # Result : ScriptingAddition # # If both arguments are nil, a ScriptingAddition object for StandardAdditions is created # and returned. This object is cached for efficiency and returned in subsequent calls; # thus clients can conveniently write (e.g): # # osax.some_command # osax.another_command # # instead of: # # sa = osax # sa.some_command # sa.another_command # # without the additional overhead of creating a new ScriptingAddition object each time. # if name == nil and app_name == nil if @_standard_additions == nil @_standard_additions = ScriptingAddition.new('StandardAdditions') end addition = @_standard_additions else if name == nil name = 'StandardAdditions' end addition = ScriptingAddition.new(name) if app_name addition = addition.by_name(app_name) end end return addition end |
.scripting_additions ⇒ Object
PUBLIC
464 465 466 467 468 |
# File 'lib/osax.rb', line 464 def OSAX.scripting_additions # list names of all currently installed scripting additions OSAX._init_caches if OSAXNames == [] return OSAXNames.clone end |
Instance Method Details
#osax(*args) ⇒ Object
514 515 516 |
# File 'lib/osax.rb', line 514 def osax(*args) return OSAX.osax(*args) end |
#scripting_additions ⇒ Object
allow methods to be included via ‘include OSAX’
510 511 512 |
# File 'lib/osax.rb', line 510 def scripting_additions return OSAX.scripting_additions end |