Method: Accessibility::Core#attribute

Defined in:
lib/accessibility/core.rb,
lib/accessibility/core.rb

#attribute(name, for_parameter: param) ⇒ Object

Fetch the given pramaeterized attribute value using the given parameter. Only AXUIElementRef objects will be given raw, Boxed objects will be unwrapped for you automatically and CFRange objects will be turned into Range objects. Similarly, you do not need to worry about wrapping the parameter as that will be done for you.

Examples:


attribute KAXStringForRangeParameterizedAttribute, for_param: 1..10
  # => "ello, worl"

Parameters:

  • attr (String)

    an attribute constant

  • param (Object)


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/accessibility/core.rb', line 98

def attribute name
  ptr = Pointer.new :id
  case code = AXUIElementCopyAttributeValue(self, name, ptr)
  when 0
    ptr.value.to_ruby
  when KAXErrorNoValue, KAXErrorAttributeUnsupported,
       KAXErrorFailure, KAXErrorInvalidUIElement then
    name == KAXChildrenAttribute ? [] : nil
  else
    handle_error code, name
  end
end