Class: OSAX::ScriptingAddition

Inherits:
Appscript::Reference show all
Defined in:
lib/osax.rb

Constant Summary

Constants inherited from Appscript::Reference

Appscript::Reference::DefaultConsiderations, Appscript::Reference::DefaultConsidersAndIgnores, Appscript::Reference::IgnoreEnums

Constants inherited from AS_SafeObject

AS_SafeObject::EXCLUDE

Instance Attribute Summary

Attributes inherited from Appscript::Reference

#AS_aem_reference, #AS_app_data

Instance Method Summary collapse

Methods inherited from Appscript::Reference

#==, #ID, #[], _pack_uint32, #_resolve_range_boundary, #_send_command, #after, #and, #any, #before, #beginning, #begins_with, #commands, #contains, #does_not_begin_with, #does_not_contain, #does_not_end_with, #elements, #end, #ends_with, #eq, #first, #ge, #gt, #hash, #help, #is_in, #is_not_in, #is_running?, #keywords, #last, #le, #lt, #methods, #middle, #ne, #next, #not, #or, #parameters, #previous, #properties, #respond_to?

Methods inherited from AS_SafeObject

hide

Constructor Details

#initialize(name, terms = nil) ⇒ ScriptingAddition

Represents a single scripting addition.



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/osax.rb', line 523

def initialize(name, terms=nil)
  # name: string -- a scripting addition's name, e.g. "StandardAdditions";
  # basically its filename minus the '.osax' suffix
  #
  # terms : module or nil -- an optional terminology glue module,
  # as exported by Terminology.dump; if given, ScriptingAddition
  # will use this instead of retrieving the terminology dynamically
  #
  # Note that name is case-insensitive and an '.osax' suffix is ignored if given.
  @_osax_name = name
  if not terms
    osax_name = name.downcase.sub(/(?i)\.osax$/, '')
    OSAX._init_caches if OSAXCache == {}
    path, terminology_tables = OSAXCache[osax_name]
    if not path
      raise ArgumentError, "Scripting addition not found: #{name.inspect}"
    end
    if not terminology_tables
      sp = OSAX::SdefParser.new
      sp.parse_file(path)
      if osax_name == 'standardadditions'
        OSAX::StandardAdditionsEnums.each { |o| sp.enumerators.push(o)}
      end
      terminology_tables = Terminology.tables_for_parsed_sdef(sp)
      OSAXCache[osax_name][1] = terminology_tables
    end
    @_terms = terminology_tables
    terms = OSAXData.new(:current, nil, @_terms)
  elsif not terms.is_a?(OSAX::OSAXData) # assume it's a glue module
    terminology_tables = Terminology.tables_for_module(terms)
    @_terms = terminology_tables
    terms = OSAXData.new(:current, nil, @_terms)
  end
  super(terms, AEM.app)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/osax.rb', line 567

def method_missing(name, *args)
  begin
    super
  rescue Appscript::CommandError => e
    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
      AE.transform_process_to_foreground_application
      activate
      super
    else
      raise
    end
  end
end

Instance Method Details

#by_aem_app(aem_app) ⇒ Object



612
613
614
615
# File 'lib/osax.rb', line 612

def by_aem_app(aem_app)
  # aem_app : AEM::Application -- an AEM::Application instance
  return ScriptingAddition.new(@_osax_name, OSAXData.new(:by_aem_app, aem_app, @_terms))
end

#by_creator(creator) ⇒ Object



596
597
598
599
600
# File 'lib/osax.rb', line 596

def by_creator(creator)
  # creator : string -- four-character creator code of application
  return ScriptingAddition.new(@_osax_name,
                               OSAXData.new(:by_path, FindApp.by_creator(creator), @_terms))
end

#by_id(id) ⇒ Object



590
591
592
593
594
# File 'lib/osax.rb', line 590

def by_id(id)
  # id : string -- bundle id of application
  return ScriptingAddition.new(@_osax_name,
                               OSAXData.new(:by_path, FindApp.by_id(id), @_terms))
end

#by_name(name) ⇒ Object

A client-created scripting addition is automatically targetted at the current application. Clients can specify another application as target by calling one of the following methods:



584
585
586
587
588
# File 'lib/osax.rb', line 584

def by_name(name)
  # name : string -- name or full path to application
  return ScriptingAddition.new(@_osax_name,
                               OSAXData.new(:by_path, FindApp.by_name(name), @_terms))
end

#by_pid(pid) ⇒ Object



602
603
604
605
# File 'lib/osax.rb', line 602

def by_pid(pid)
  # pid : integer -- Unix process id
  return ScriptingAddition.new(@_osax_name, OSAXData.new(:by_pid, pid, @_terms))
end

#by_url(url) ⇒ Object



607
608
609
610
# File 'lib/osax.rb', line 607

def by_url(url)
  # url : string -- eppc URL of application
  return ScriptingAddition.new(@_osax_name, OSAXData.new(:by_url, url, @_terms))
end

#currentObject



617
618
619
# File 'lib/osax.rb', line 617

def current
  return ScriptingAddition.new(@_osax_name, OSAXData.new(:current, nil, @_terms))
end

#to_sObject Also known as: inspect



559
560
561
# File 'lib/osax.rb', line 559

def to_s
  return "#<OSAX::ScriptingAddition name=#{@_osax_name.inspect} target=#{@AS_app_data.target.inspect}>"
end