Class: AX::SystemWide
- Includes:
- Accessibility::Keyboard
- 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).
Class Method Summary collapse
-
.desktop ⇒ AX::Group
Find and return the group that represents the desktop.
-
.status_items ⇒ AX::MenuBarItem
Find and return menu bar items for the system.
Instance Method Summary collapse
-
#element_at(point) ⇒ AX::Element?
Find the element in at the given point for the topmost appilcation window.
-
#focused_application ⇒ AX::Application
Find and return the application which is frontmost.
-
#hold_modifier(key) ⇒ Number?
Press the given modifier key and hold it down while yielding to the given block.
-
#initialize ⇒ SystemWide
constructor
Overridden since there is only one way to get the element ref.
-
#on_notification(*args) ⇒ Object
Raises an
NoMethodError
instead of (possibly) silently failing to register for a notification. -
#search(*args) ⇒ Object
The system wide object cannot be used to perform searches.
-
#set_global_timeout(seconds) ⇒ Number
Set the global messaging timeout.
-
#type(string) ⇒ Boolean
(also: #type_string)
Send keyboard input to the focused control element.
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?, #screenshot, #set, #size_of, #to_h, #to_point, #to_s, #writable?
Methods included from Accessibility::PrettyPrinter
#pp_checkbox, #pp_children, #pp_enabled, #pp_focused, #pp_identifier, #pp_position
Constructor Details
#initialize ⇒ SystemWide
Overridden since there is only one way to get the element ref.
42 43 44 |
# File 'lib/ax/systemwide.rb', line 42 def initialize super Accessibility::Element.system_wide end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AX::Element
Class Method Details
.desktop ⇒ AX::Group
Find and return the group that represents the desktop
19 20 21 |
# File 'lib/ax/systemwide.rb', line 19 def desktop AX::Application.finder.scroll_areas.first.groups.first end |
.status_items ⇒ AX::MenuBarItem
This currently does not include spotlight or the notification center as they interact oddly with accessibility APIs and how AXElements handle errors
Find and return menu bar items for the system
That is, menu bar items that do not belong to the current app, but that belong to the system, such as the clock or wi-fi menu.
35 36 37 |
# File 'lib/ax/systemwide.rb', line 35 def status_items AX::Application.new('SystemUIServer')..children end |
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.
107 108 109 |
# File 'lib/ax/systemwide.rb', line 107 def element_at point @ref.element_at(point).to_ruby end |
#focused_application ⇒ AX::Application
Find and return the application which is frontmost
This is often, but not necessarily, the same as the app that owns the menu bar.
123 124 125 |
# File 'lib/ax/systemwide.rb', line 123 def focused_application AX::Application.frontmost_app end |
#hold_modifier(key) ⇒ Number?
Press the given modifier key and hold it down while yielding to the given block.
73 74 75 76 77 78 79 80 81 |
# File 'lib/ax/systemwide.rb', line 73 def hold_modifier key code = EventGenerator::CUSTOM[key] raise ArgumentError, "Invalid modifier `#{key}' given" unless code KeyCoder.post_event([code, true]) yield ensure # if block raises the button might stuck, so ensure it is released KeyCoder.post_event([code, false]) if code code end |
#on_notification(*args) ⇒ Object
Raises an NoMethodError
instead of (possibly) silently failing to
register for a notification.
95 96 97 |
# File 'lib/ax/systemwide.rb', line 95 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.
86 87 88 |
# File 'lib/ax/systemwide.rb', line 86 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.
118 119 120 |
# File 'lib/ax/systemwide.rb', line 118 def set_global_timeout seconds @ref.set_timeout_to seconds end |
#type(string) ⇒ Boolean Also known as: type_string
Send keyboard input to the focused control element.
For details on how to format the string, check out the Keyboarding documentation.
54 55 56 57 58 |
# File 'lib/ax/systemwide.rb', line 54 def type string keyboard_events_for(string).each do |event| KeyCoder.post_event event end end |