HSAXElement
TypeObject representing an Accessibility element. You should not instantiate this directly, but rather, use the hs.ax methods to create these as required.
Properties
Methods
children() -> HSAXElement[]
The element's children
children() -> HSAXElement[]
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 |
const el = hs.ax.focusedElement()
const child = el.childAtIndex(0)
attributeNames() -> string[]
Get all available attribute names
attributeNames() -> string[]
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 |
const el = hs.ax.focusedElement()
console.log(el.attributeValue("AXTitle"))
setAttributeValue(attribute, value) -> boolean
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.
setAttributeValue(attribute, value) -> boolean
| Name | Type | Description |
|---|---|---|
| attribute | string | The attribute name to set |
| value | JSValue | The value to set |
true if the attribute was set. Failures throw rather than returning false.const el = hs.ax.focusedElement()
el.setAttributeValue("AXValue", "Hello")
const win = hs.ax.windowElement(hs.window.focusedWindow())
win.setAttributeValue("AXPosition", new HSPoint(100, 100))
win.setAttributeValue("AXSize", new HSSize(800, 600))
try {
win.setAttributeValue("AXFullScreen", true)
} catch (err) {
console.error(err.message, err.code)
}
isAttributeSettable(attribute) -> boolean
Check if an attribute is settable
isAttributeSettable(attribute) -> boolean
| Name | Type | Description |
|---|---|---|
| attribute | string | An attribute name |
const el = hs.ax.focusedElement()
console.log(el.isAttributeSettable("AXValue"))
actionNames() -> string[]
Get all available action names
actionNames() -> string[]
const el = hs.ax.focusedElement()
console.log(el.actionNames())
performAction(action) -> boolean
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.
performAction(action) -> boolean
| Name | Type | Description |
|---|---|---|
| action | string | The action to perform |
true if the action was performed. Failures throw rather than returning false.const el = hs.ax.focusedElement()
try {
el.performAction("AXPress")
} catch (err) {
console.error(err.message, err.code)
}
isEqualToElement(other) -> boolean
Test whether this element and another refer to the same underlying accessibility object
isEqualToElement(other) -> boolean
| Name | Type | Description |
|---|---|---|
| other | HSAXElement | Another HSAXElement to compare against |
const el1 = hs.ax.focusedElement()
const el2 = hs.ax.focusedElement()
console.log(el1.isEqualToElement(el2)) // true, assuming focus hasn't changed