class AX::SystemWide
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).
Public Class Methods
Find and return the group that represents the desktop
@return [AX::Group]
# File lib/ax/systemwide.rb, line 19 def desktop AX::Application.finder.scroll_areas.first.groups.first end
Overridden since there is only one way to get the element ref.
AX::Element::new
# File lib/ax/systemwide.rb, line 42 def initialize super Accessibility::Element.system_wide end
@note 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.
@return [AX::MenuBarItem]
# File lib/ax/systemwide.rb, line 35 def status_items AX::Application.new('SystemUIServer').menu_bar.children end
Public Instance Methods
Find the element in at the given point for the topmost appilcation window.
‘nil` will be returned if there was nothing at that point.
@param point [#to_point] @return [AX::Element,nil]
# File lib/ax/systemwide.rb, line 107 def element_at point @ref.element_at(point).to_ruby end
(see AX::Application.frontmost_application
)
# File lib/ax/systemwide.rb, line 123 def focused_application AX::Application.frontmost_app end
Press the given modifier key and hold it down while yielding to the given block.
@example
hold_modifier "\\CONTROL" do drag_mouse_to point end
@param key [String] @return [Number,nil]
# 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
Raises an ‘NoMethodError` instead of (possibly) silently failing to register for a notification.
@raise [NoMethodError]
# File lib/ax/systemwide.rb, line 95 def on_notification *args raise NoMethodError, 'AX::SystemWide cannot register for notifications' end
The system wide object cannot be used to perform searches. This method is just an override to avoid a difficult to understand error messages.
# File lib/ax/systemwide.rb, line 86 def search *args raise NoMethodError, 'AX::SystemWide cannot search' end
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.
@param seconds [Number] @return [Number]
# File lib/ax/systemwide.rb, line 118 def set_global_timeout seconds @ref.set_timeout_to seconds end
Send keyboard input to the focused control element.
For details on how to format the string, check out the [Keyboarding documentation](github.com/Marketcircle/AXElements/wiki/Keyboarding).
@param string [String] @return [Boolean]
# File lib/ax/systemwide.rb, line 54 def type string keyboard_events_for(string).each do |event| KeyCoder.post_event event end end