Class: AX::SystemWide
- Inherits:
-
Element
- Object
- Element
- AX::SystemWide
- 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).
Constant Summary
Class Method Summary (collapse)
-
+ (AX::Group) desktop
Find and return the group that represents the desktop.
-
+ (AX::MenuBarItem) status_items
Find and return menu bar items for the system.
Instance Method Summary (collapse)
-
- (AX::Element?) element_at(point)
Find the element in at the given point for the topmost appilcation window.
-
- (AX::Application) focused_application
Find and return the application which is frontmost.
-
- (Number?) hold_modifier(key)
Press the given modifier key and hold it down while yielding to the given block.
-
- (SystemWide) initialize
constructor
Overridden since there is only one way to get the element ref.
-
- (Object) on_notification(*args)
Raises an
NoMethodErrorinstead of (possibly) silently failing to register for a notification. -
- (Object) search(*args)
The system wide object cannot be used to perform searches.
-
- (Number) set_global_timeout(seconds)
Set the global messaging timeout.
-
- (Boolean) type(string)
(also: #type_string)
Generate keyboard events by simulating keyboard input.
Methods included from Accessibility::String
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::PrettyPrinter
#pp_checkbox, #pp_children, #pp_identifier, #pp_position
Constructor Details
- (SystemWide) initialize
Overridden since there is only one way to get the element ref.
43 44 45 |
# File 'lib/ax/systemwide.rb', line 43 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
+ (AX::Group) desktop
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 |
+ (AX::MenuBarItem) status_items
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
- (AX::Element?) element_at(point)
Find the element in at the given point for the topmost appilcation window.
nil will be returned if there was nothing at that point.
111 112 113 |
# File 'lib/ax/systemwide.rb', line 111 def element_at point @ref.element_at(point).to_ruby end |
- (AX::Application) focused_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.
127 128 129 |
# File 'lib/ax/systemwide.rb', line 127 def focused_application AX::Application.frontmost_app end |
- (Number?) hold_modifier(key)
Press the given modifier key and hold it down while yielding to the given block.
77 78 79 80 81 82 83 84 85 |
# File 'lib/ax/systemwide.rb', line 77 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 |
- (Object) on_notification(*args)
Raises an NoMethodError instead of (possibly) silently failing to
register for a notification.
99 100 101 |
# File 'lib/ax/systemwide.rb', line 99 def on_notification *args raise NoMethodError, 'AX::SystemWide cannot register for notifications' end |
- (Object) search(*args)
The system wide object cannot be used to perform searches. This method is just an override to avoid a difficult to understand error messages.
90 91 92 |
# File 'lib/ax/systemwide.rb', line 90 def search *args raise NoMethodError, 'AX::SystemWide cannot search' end |
- (Number) set_global_timeout(seconds)
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.
122 123 124 |
# File 'lib/ax/systemwide.rb', line 122 def set_global_timeout seconds @ref.set_timeout_to seconds end |
- (Boolean) type(string) Also known as: type_string
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.
59 60 61 62 |
# File 'lib/ax/systemwide.rb', line 59 def type string @ref.post keyboard_events_for string true end |