hammerspoon2-docs
    Preparing search index...

    Class HSAXElement

    Object representing an Accessibility element. You should not instantiate this directly, but rather, use the hs.ax methods to create these as required.

    Index

    Constructors

    Properties

    elementDescription: string | null

    The element's description

    frame: HSRect | null

    The element's frame (position and size combined)

    isEnabled: boolean

    Whether the element is enabled

    isFocused: boolean

    Whether the element is focused

    parent: HSAXElement | null

    The element's parent

    pid: number

    Get the process ID of the application that owns this element

    position: HSPoint | null

    The element's position on screen

    role: string | null

    The element's role (e.g., "AXWindow", "AXButton")

    size: HSSize | null

    The element's size

    subrole: string | null

    The element's subrole

    title: string | null

    The element's title

    value: any

    The element's value

    Methods

    • Get all available action names

      Returns string[]

      An array of available action names

    • Get all available attribute names

      Returns string[]

      An array of attribute names

    • Get the value of a specific attribute

      Parameters

      • attribute: string

        The attribute name to fetch the value for

      Returns any

      The requested value, or nil if none was found

    • Get a specific child by index

      Parameters

      • index: number

        The index to fetch

      Returns HSAXElement | null

      An HSAXElement object, if a child exists at the given index

    • Check if an attribute is settable

      Parameters

      • attribute: string

        An attribute name

      Returns boolean

      True if the attribute is settable, otherwise False

    • Test whether this element and another refer to the same underlying accessibility object

      Parameters

      • other: HSAXElement

        Another HSAXElement to compare against

      Returns boolean

      True if both objects represent the same underlying accessibility element

    • Perform a specific action If the Accessibility API refuses the action, this throws an Error whose message says why, and whose code property is the Accessibility error's name, e.g. "kAXErrorActionUnsupported" or "kAXErrorAttributeUnsupported" (the element doesn't have the action; AppKit applications report the latter) or "kAXErrorCannotComplete" (the application didn't respond). Use actionNames() to see which actions an element supports.

      Parameters

      • action: string

        The action to perform

      Returns boolean

      true if the action was performed. Failures throw rather than returning false.

      Throws an Error on failure; wrap calls in try/catch to handle it.

    • Set the value of a specific attribute The value must be of the type the Accessibility API expects for the attribute. For the well-known attributes below the type is checked first, and a value of the wrong type throws an error naming the expected type.

      Attribute Expected value
      AXPosition an HSPoint
      AXSize an HSSize
      AXFrame an HSRect
      AXFocused, AXMain, AXMinimized, AXHidden, AXFrontmost, AXFullScreen, AXSelected, AXExpanded, AXDisclosing, AXEnhancedUserInterface a boolean
      AXSelectedText a string
      Plain objects such as {x: 1, y: 2} are not accepted for geometry attributes; use new HSPoint(1, 2).
      If the Accessibility API refuses the change, this throws an Error whose message says why, and whose
      code property is the Accessibility error's name, e.g. "kAXErrorAttributeUnsupported" (the element
      doesn't have the attribute), "kAXErrorIllegalArgument" (the value isn't valid for it) or
      "kAXErrorCannotComplete" (the application didn't respond). A value of the wrong type for one of
      the attributes above throws an Error with no code.

      Parameters

      • attribute: string

        The attribute name to set

      • value: any

        The value to set

      Returns boolean

      true if the attribute was set. Failures throw rather than returning false.

      Throws an Error on failure; wrap calls in try/catch to handle it.