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/internal.m |
Signature | hs.axuielement.attributes[] |
---|---|
Type | Constant |
Description | A table of common accessibility object attribute names which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#matchesCriteria) as keys in the match criteria argument. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.orientations[] |
---|---|
Type | Constant |
Description | A table of orientation types which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#matchesCriteria) as attribute values for "AXOrientation" in the match criteria argument. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.parameterizedAttributes[] |
---|---|
Type | Constant |
Description | A table of common accessibility object parameterized attribute names, provided for reference. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.roles[] |
---|---|
Type | Constant |
Description | A table of common accessibility object roles which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#matchesCriteria) as attribute values for "AXRole" in the match criteria argument. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.rulerMarkers[] |
---|---|
Type | Constant |
Description | A table of ruler marker types which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#matchesCriteria) as attribute values for "AXMarkerType" in the match criteria argument. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.sortDirections[] |
---|---|
Type | Constant |
Description | A table of sort direction types which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#matchesCriteria) as attribute values for "AXSortDirection" in the match criteria argument. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.subroles[] |
---|---|
Type | Constant |
Description | A table of common accessibility object subroles which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#matchesCriteria) as attribute values for "AXSubrole" in the match criteria argument. |
Notes | |
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.units[] |
---|---|
Type | Constant |
Description | A table of measurement unit types which may be used with [hs.axuielement:elementSearch](#elementSearch) or [hs.axuielement:matchesCriteria](#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/internal.m |
Signature | hs.axuielement.searchCriteriaFunction(criteria) -> function |
---|---|
Type | Function |
Description | Returns a function for use with [hs.axuielement:elementSearch](#elementSearch) that uses [hs.axuielement:matchesCriteria](#matchesCriteria) with the specified criteria. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/init.lua |
Signature | hs.axuielement.applicationElement(applicationObject) -> axuielementObject |
---|---|
Type | Constructor |
Description | Returns the top-level accessibility object for the application specified by the `hs.application` object. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/internal.m |
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/internal.m |
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/init.lua |
Signature | hs.axuielement.systemWideElement() -> axuielementObject |
---|---|
Type | Constructor |
Description | Returns an accessibility object that provides access to system attributes. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement.windowElement(windowObject) -> axuielementObject |
---|---|
Type | Constructor |
Description | Returns the accessibility object for the window specified by the `hs.window` object. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/internal.m |
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/internal.m |
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/internal.m |
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/internal.m |
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/init.lua |
Signature | hs.axuielement:asHSApplication() -> hs.application object | nil |
---|---|
Type | Method |
Description | If the element referes to an application, return an `hs.application` object for the element. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/internal.m |
Signature | hs.axuielement:asHSWindow() -> hs.window object | nil |
---|---|
Type | Method |
Description | If the element referes to a window, return an `hs.window` object for the element. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/axuielement/internal.m |
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/internal.m |
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/internal.m |
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/internal.m |
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/init.lua |
Signature | hs.axuielement:copy() -> axuielementObject |
---|---|
Type | Method |
Description | Return a duplicate userdata reference to the Accessibility object. |
Parameters |
|
Returns |
|
Source | extensions/axuielement/internal.m |
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/internal.m |
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/init.lua |
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/internal.m |
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/internal.m |
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/init.lua |
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/internal.m |
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/internal.m |
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/init.lua |
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/internal.m |
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/internal.m |
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/internal.m |
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/internal.m |