Class: AX::SystemWide

Inherits:
Element show all
Includes:
Accessibility::String
Defined in:
lib/ax/systemwide.rb

Overview

Represents the special SystemWide accessibility object.

Previously, this object was a singleton, but that apparently causes problems with the AXAPIs. So you should always create a new instance of the system wide object when you need to use it (even though they are all the same thing).

Instance Method Summary collapse

Methods included from Accessibility::String

#keyboard_events_for

Methods inherited from Element

#==, #actions, #ancestor, #ancestry, #application, #attribute, #attributes, #blank?, #bounds, #children, #description, #inspect, #inspect_subtree, #invalid?, #method_missing, #methods, #parameterized_attribute, #parameterized_attributes, #perform, #pid, #respond_to?, #set, #size_of, #to_point, #to_s, #writable?

Methods included from Accessibility::Factory

#process

Methods included from Accessibility::PPInspector

#pp_checkbox, #pp_children, #pp_identifier, #pp_position

Constructor Details

#initializeSystemWide

Overridden since there is only one way to get the element ref.



16
17
18
# File 'lib/ax/systemwide.rb', line 16

def initialize
  super AXUIElementCreateSystemWide()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AX::Element

Instance Method Details

#element_at(point) ⇒ AX::Element?

Find the element in at the given point for the topmost appilcation window.

nil will be returned if there was nothing at that point.

Parameters:

Returns:



83
84
85
# File 'lib/ax/systemwide.rb', line 83

def element_at point
  process @ref.element_at point
end

#hold_modifier(key) ⇒ Number?

Press the given modifier key and hold it down while yielding to the given block.

Examples:


hold_key "\\CONTROL" do
  drag_mouse_to point
end

Parameters:

  • (String)

Returns:

  • (Number, nil)


49
50
51
52
53
54
55
56
57
# File 'lib/ax/systemwide.rb', line 49

def hold_modifier key
  code = EventGenerator::CUSTOM[key]
  raise ArgumentError, "Invalid modifier `#{key}' given" unless code
  @ref.post [[code, true]]
  yield
ensure # if block raises the button might stuck, so ensure it is released
  @ref.post [[code,false]] if code
  code
end

#on_notification(*args) ⇒ Object

Raises an NoMethodError instead of (possibly) silently failing to register for a notification.

Raises:

  • (NoMethodError)


71
72
73
# File 'lib/ax/systemwide.rb', line 71

def on_notification *args
  raise NoMethodError, 'AX::SystemWide cannot register for notifications'
end

#search(*args) ⇒ Object

The system wide object cannot be used to perform searches. This method is just an override to avoid a difficult to understand error messages.

Raises:

  • (NoMethodError)


62
63
64
# File 'lib/ax/systemwide.rb', line 62

def search *args
  raise NoMethodError, 'AX::SystemWide cannot search'
end

#set_global_timeout(seconds) ⇒ Number

Set the global messaging timeout. Searching through another interface and looking up attributes incurs a lot of IPC calls and sometimes an app is slow to respond.

Parameters:

  • (Number)

Returns:

  • (Number)


94
95
96
# File 'lib/ax/systemwide.rb', line 94

def set_global_timeout seconds
  @ref.set_timeout_to seconds
end

#type(string) ⇒ Boolean Also known as: type_string

Note:

With the SystemWide class, using #type will send the events to which ever app has focus.

Generate keyboard events by simulating keyboard input.

See the Keyboarding documentation for more information on how to format strings.

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/ax/systemwide.rb', line 31

def type string
  @ref.post keyboard_events_for string
  true
end