API Docs

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

Properties

role

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

isEnabled

boolean
Whether the element is enabled

isFocused

boolean
Whether the element is focused

position

HSPoint
The element's position on screen

frame

HSRect
The element's frame (position and size combined)

pid

number
Get the process ID of the application that owns this element

Methods

children() -> HSAXElement[]

The element's children
children() -> HSAXElement[]
HSAXElement[]
An array of HSAXElement objects
const el = hs.ax.focusedElement()
console.log(el.children().length)

childAtIndex(index) -> HSAXElement

Get a specific child by index
childAtIndex(index) -> HSAXElement
Name Type Description
index number The index to fetch
HSAXElement
An HSAXElement object, if a child exists at the given index
const el = hs.ax.focusedElement()
const child = el.childAtIndex(0)

attributeNames() -> string[]

Get all available attribute names
attributeNames() -> string[]
string[]
An array of attribute names
const el = hs.ax.focusedElement()
console.log(el.attributeNames())

attributeValue(attribute) -> any

Get the value of a specific attribute
attributeValue(attribute) -> any
Name Type Description
attribute string The attribute name to fetch the value for
any
The requested value, or nil if none was found
const el = hs.ax.focusedElement()
console.log(el.attributeValue("AXTitle"))

setAttributeValue(attribute, value) -> boolean

Set the value of a specific attribute
setAttributeValue(attribute, value) -> boolean
Name Type Description
attribute string The attribute name to set
value any The value to set
boolean
True if the operation succeeded, otherwise False
const el = hs.ax.focusedElement()
el.setAttributeValue("AXValue", "Hello")

isAttributeSettable(attribute) -> boolean

Check if an attribute is settable
isAttributeSettable(attribute) -> boolean
Name Type Description
attribute string An attribute name
boolean
True if the attribute is settable, otherwise False
const el = hs.ax.focusedElement()
console.log(el.isAttributeSettable("AXValue"))

actionNames() -> string[]

Get all available action names
actionNames() -> string[]
string[]
An array of available action names
const el = hs.ax.focusedElement()
console.log(el.actionNames())

performAction(action) -> boolean

Perform a specific action
performAction(action) -> boolean
Name Type Description
action string The action to perform
boolean
True if the action succeeded, otherwise False
const el = hs.ax.focusedElement()
el.performAction("AXPress")