This module allows you to access the accessibility objects of running applications, their windows, menus, and other user interface elements that support the OS X accessibility API.
This module works through the use of axuielementObjects, which is the Hammerspoon representation for an accessibility object. An accessibility object represents any object or component of an OS X application which can be manipulated through the OS X Accessibility API -- it can be an application, a window, a button, selected text, etc. As such, it can only support those features and objects within an application that the application developers make available through the Accessibility API.
In addition to the formal methods described in this documentation, dynamic methods exist for accessing element attributes and actions. These will differ somewhat between objects as the specific attributes and actions will depend upon the accessibility object's role and purpose, but the following outlines the basics.
Getting and Setting Attribute values:
object.attribute
is a shortcut for object:attributeValue(attribute)
object.attribute = value
is a shortcut for object:setAttributeValue(attribute, value)
Iteration over Attributes:
for k,v in pairs(object) do ... end
is a shortcut for for k,_ in ipairs(object:attributeNames()) do local v = object:attributeValue(k) ; ... end
or for k,v in pairs(object:allAttributeValues()) do ... end
(though see note below)nil
prevents the key from being retained in the table returned. See hs.axuielement:allAttributeValues for details and a workaround.Iteration over Child Elements (AXChildren):
for i,v in ipairs(object) do ... end
is a shortcut for for i,v in pairs(object:attributeValue("AXChildren") or {}) do ... end
object:attributeValue("AXChildren")
may return nil if the object does not have the AXChildren
attribute; the shortcut does not have this limitation.#object
is a shortcut for #object:attributeValue("AXChildren")
object[i]
is a shortcut for object:attributeValue("AXChildren")[i]
Actions (hs.axuielement:actionNames):
object:do<action>()
is a shortcut for object:performAction(action)
ParameterizedAttributes:
object:<attribute>WithParameter(value)
is a shortcut for `object:parameterizedAttributeValue(attribute, value)
See hs.axuielement:parameterizedAttributeValue for a description of the return values and hs.axuielement:parameterizedAttributeNames to get a list of parameterized values that the element supports
The specific value required for a each parameterized attribute is different and is often application specific thus requiring some experimentation. Notes regarding identified parameter types and thoughts on some still being investigated will be provided in the Hammerspoon Wiki, hopefully shortly after this module becomes part of a Hammerspoon release.
Signature | hs.axuielement.actions[] |
---|---|
Type | Constant |
Description |
A table of common accessibility object action names, provided for reference. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 966 |
Signature | hs.axuielement.attributes[] |
---|---|
Type | Constant |
Description |
A table of common accessibility object attribute names which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as keys in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 743 |
Signature | hs.axuielement.orientations[] |
---|---|
Type | Constant |
Description |
A table of orientation types which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as attribute values for "AXOrientation" in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 1127 |
Signature | hs.axuielement.parameterizedAttributes[] |
---|---|
Type | Constant |
Description |
A table of common accessibility object parameterized attribute names, provided for reference. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 926 |
Signature | hs.axuielement.roles[] |
---|---|
Type | Constant |
Description |
A table of common accessibility object roles which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as attribute values for "AXRole" in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 990 |
Signature | hs.axuielement.rulerMarkers[] |
---|---|
Type | Constant |
Description |
A table of ruler marker types which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as attribute values for "AXMarkerType" in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 1159 |
Signature | hs.axuielement.sortDirections[] |
---|---|
Type | Constant |
Description |
A table of sort direction types which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as attribute values for "AXSortDirection" in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 1143 |
Signature | hs.axuielement.subroles[] |
---|---|
Type | Constant |
Description |
A table of common accessibility object subroles which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as attribute values for "AXSubrole" in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 1067 |
Signature | hs.axuielement.units[] |
---|---|
Type | Constant |
Description |
A table of measurement unit types which may be used with hs.axuielement:elementSearch or hs.axuielement:matchesCriteria as attribute values for attributes which specify measurement unit types (e.g. "AXUnits", "AXHorizontalUnits", and "AXVerticalUnits") in the match criteria argument. |
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 1180 |
Signature | hs.axuielement.searchCriteriaFunction(criteria) -> function |
---|---|
Type | Function |
Description |
Returns a function for use with hs.axuielement:elementSearch that uses hs.axuielement:matchesCriteria with the specified criteria. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/axuielement.lua line 464 |
Signature | hs.axuielement.applicationElement(applicationObject) -> axuielementObject |
---|---|
Type | Constructor |
Description |
Returns the top-level accessibility object for the application specified by the |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 98 |
Signature | hs.axuielement.applicationElementForPID(pid) -> axuielementObject |
---|---|
Type | Constructor |
Description |
Returns the top-level accessibility object for the application with the specified process ID. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 144 |
Signature | hs.axuielement.systemElementAtPosition(x, y | pointTable) -> axuielementObject |
---|---|
Type | Constructor |
Description |
Returns the accessibility object at the specified position on the screen. The top-left corner of the primary screen is 0, 0. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 86 |
Signature | hs.axuielement.systemWideElement() -> axuielementObject |
---|---|
Type | Constructor |
Description |
Returns an accessibility object that provides access to system attributes. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 126 |
Signature | hs.axuielement.windowElement(windowObject) -> axuielementObject |
---|---|
Type | Constructor |
Description |
Returns the accessibility object for the window specified by the |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 70 |
Signature | hs.axuielement:actionDescription(action) -> string | nil, errString |
---|---|
Type | Method |
Description |
Returns a localized description of the specified accessibility object's action. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 254 |
Signature | hs.axuielement:actionNames() -> table | nil, errString |
---|---|
Type | Method |
Description |
Returns a list of all the actions the specified accessibility object can perform. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 221 |
Signature | hs.axuielement:allAttributeValues([includeErrors]) -> table | nil, errString |
---|---|
Type | Method |
Description |
Returns a table containing key-value pairs for all attributes of the accessibility object. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 315 |
Signature | hs.axuielement:allDescendantElements(callback, [withParents]) -> elementSearchObject |
---|---|
Type | Method |
Description |
Query the accessibility object for all child accessibility objects and their descendants |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 502 |
Signature | hs.axuielement:asHSApplication() -> hs.application object | nil |
---|---|
Type | Method |
Description |
If the element refers to an application, return an |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 645 |
Signature | hs.axuielement:asHSWindow() -> hs.window object | nil |
---|---|
Type | Method |
Description |
If the element refers to a window, return an |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 680 |
Signature | hs.axuielement:attributeNames() -> table | nil, errString |
---|---|
Type | Method |
Description |
Returns a list of all the attributes supported by the specified accessibility object. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 188 |
Signature | hs.axuielement:attributeValue(attribute) -> value | nil, errString |
---|---|
Type | Method |
Description |
Returns the value of an accessibility object's attribute. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 286 |
Signature | hs.axuielement:attributeValueCount(attribute) -> integer | nil, errString |
---|---|
Type | Method |
Description |
Returns the count of the array of an accessibility object's attribute value. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 365 |
Signature | hs.axuielement:buildTree(callback, [depth], [withParents]) -> elementSearchObject |
---|---|
Type | Method |
Description |
Captures all of the available information for the accessibility object and its descendants and returns it in a table for inspection. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 478 |
Signature | hs.axuielement:childrenWithRole(role) -> table |
---|---|
Type | Method |
Description |
Returns a table containing only those immediate children of the element that perform the specified role. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 972 |
Signature | hs.axuielement:copy() -> axuielementObject |
---|---|
Type | Method |
Description |
Return a duplicate userdata reference to the Accessibility object. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 171 |
Signature | hs.axuielement:elementAtPosition(x, y | pointTable) -> axuielementObject | nil, errString |
---|---|
Type | Method |
Description |
Returns the accessibility object at the specified position on the screen. The top-left corner of the primary screen is 0, 0. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 533 |
Signature | hs.axuielement:elementSearch(callback, [criteria], [namedModifiers]) -> elementSearchObject |
---|---|
Type | Method |
Description |
Search for and generate a table of the accessibility elements for the attributes and descendants of this object based on the specified criteria. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 766 |
Signature | hs.axuielement:isAttributeSettable(attribute) -> boolean | nil, errString |
---|---|
Type | Method |
Description |
Returns whether the specified accessibility object's attribute can be modified. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 421 |
Signature | hs.axuielement:isValid() -> boolean | nil, errString |
---|---|
Type | Method |
Description |
Returns whether the specified accessibility object is still valid. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 447 |
Signature | hs.axuielement:matchesCriteria(criteria) -> boolean |
---|---|
Type | Method |
Description |
Returns true if the axuielementObject matches the specified criteria or false if it does not. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 265 |
Signature | hs.axuielement:parameterizedAttributeNames() -> table | nil, errString |
---|---|
Type | Method |
Description |
Returns a list of all the parameterized attributes supported by the specified accessibility object. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 391 |
Signature | hs.axuielement:parameterizedAttributeValue(attribute, parameter) -> value | nil, errString |
---|---|
Type | Method |
Description |
Returns the value of an accessibility object's parameterized attribute. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 582 |
Signature | hs.axuielement:path() -> table |
---|---|
Type | Method |
Description |
Returns a table of axuielements tracing this object through its parent objects to the root for this element, most likely an application object or the system wide object. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/axuielement.lua line 211 |
Signature | hs.axuielement:performAction(action) -> axuielement | false | nil, errString |
---|---|
Type | Method |
Description |
Requests that the specified accessibility object perform the specified action. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 503 |
Signature | hs.axuielement:pid() -> integer | nil, errString |
---|---|
Type | Method |
Description |
Returns the process ID associated with the specified accessibility object. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 478 |
Signature | hs.axuielement:setAttributeValue(attribute, value) -> axuielementObject | nil, errString |
---|---|
Type | Method |
Description |
Sets the accessibility object's attribute to the specified value. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/libaxuielement.m line 617 |
Signature | hs.axuielement:setTimeout(value) -> axuielementObject | nil, errString |
---|---|
Type | Method |
Description |
Sets the timeout value used accessibility queries performed from this element. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/libaxuielement.m line 710 |
© 2014–2017 Hammerspoon contributors
Licensed under the MIT License.
https://www.hammerspoon.org/docs/hs.axuielement.html