#cp.ui.axutils

Utility functions to support hs.axuielement.


#Submodules


#API Overview

Functions - API calls offered directly by the extension


#API Documentation

#Functions

Signaturecp.ui.axutils.cache(source, key, finderFn[, verifyFn]) -> axuielement
TypeFunction
DescriptionChecks if the cached value at the source[key] is a valid axuielement. If not it will call the provided finderFn() function (with no arguments), cache the result and return it.
Parameters
  • source - the table containing the cache
  • key - the key the value is cached under
  • finderFn - the function which will return the element if not found.
  • [verifyFn] - an optional function which will check the cached element to verify it is still valid.
Returns
  • The valid cached value.
Notes
  • If the optional verifyFn is provided, it will be called to check that the cached value is still valid. It is passed a single parameter (the axuielement) and is expected to return true or false.
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 654

Signaturecp.ui.axutils.childAtIndex(element, index, compareFn[, matcherFn]) -> axuielement
TypeFunction
DescriptionSearches for the child element which is at number index when sorted using the compareFn.
Parameters
  • element - the axuielement or array of axuielements
  • index - the index number of the child to find.
  • compareFn - a function to compare the elements.
  • matcherFn - an optional function which is passed each child and returns true if the child should be processed.
Returns
  • The child, or nil if the index is larger than the number of children.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 385

Signaturecp.ui.axutils.childFromBottom(element, index, matcherFn) -> axuielement
TypeFunction
DescriptionSearches for the child element which is at number index when sorted bottom-to-top.
Parameters
  • element - the axuielement or array of axuielements
  • index - the index number of the child to find.
  • matcherFn - an optional function which is passed each child and returns true if the child should be processed.
Returns
  • The child, or nil if the index is larger than the number of children.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 528

Signaturecp.ui.axutils.childFromLeft(element, index[, matcherFn]) -> axuielement
TypeFunction
DescriptionSearches for the child element which is at number index when sorted left-to-right.
Parameters
  • element - the axuielement or array of axuielements
  • index - the index number of the child to find.
  • matcherFn - an optional function which is passed each child and returns true if the child should be processed.
Returns
  • The child, or nil if the index is larger than the number of children.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 483

Signaturecp.ui.axutils.childFromRight(element, index[, matcherFn]) -> axuielement
TypeFunction
DescriptionSearches for the child element which is at number index when sorted right-to-left.
Parameters
  • element - the axuielement or array of axuielements
  • index - the index number of the child to find.
  • matcherFn - an optional function which is passed each child and returns true if the child should be processed.
Returns
  • The child, or nil if the index is larger than the number of children.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 498

Signaturecp.ui.axutils.childFromTop(element, index[, matcherFn]) -> axuielement
TypeFunction
DescriptionSearches for the child element which is at number index when sorted top-to-bottom.
Parameters
  • element - the axuielement or array of axuielements
  • index - the index number of the child to find.
  • matcherFn - an optional function which is passed each child and returns true if the child should be processed.
Returns
  • The child, or nil if the index is larger than the number of children.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 513

Signaturecp.ui.axutils.childInColumn(element, role, startIndex, childIndex) -> table | nil
TypeFunction
DescriptionFinds the children for an element, then checks to see if they match the supplied role. It then compares the vertical position data of all matching children and returns an element defined by the childIndex, which lines up vertially with the element defined by the startIndex.
Parameters
  • element - The element to retrieve the children from.
  • role - The required role as a string.
  • startIndex - A number which defines the index of the first element to use.
  • childIndex - A number which defines the index of the element to return.
Returns
  • The axuielement if it matches, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 133

Signaturecp.ui.axutils.childIndex(element) -> number or nil
TypeFunction
DescriptionFinds the index of the specified child element, if it is present. If not, nil is returned.
Parameters
  • element - The axuielement to find the index of.
Returns
  • The index (1 or higher) of the element, or nil if it was not found.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 603

Signaturecp.ui.axutils.childMatching(element, matcherFn[, index]) -> axuielement
TypeFunction
DescriptionThis searches for the first child of the specified element for which the provided function returns true. The function will receive one parameter - the current child.
Parameters
  • element - the axuielement
  • matcherFn - the function which checks if the child matches the requirements.
  • index - the number of matching child to return. Defaults to 1.
Returns
  • The first matching child, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 354

Signaturecp.ui.axutils.children(element[, compareFn]) -> table
TypeFunction
DescriptionFinds the children for the element. If it is an hs.axuielement, it will attempt to get the AXChildren attribute. If it is a table with a children function, that will get called. If no children exist, an empty table will be returned.
Parameters
  • element - The element to retrieve the children of.
  • compareFn - Optional function to use to sort the order of the returned children.
Returns
  • a table of children
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 149

Signaturecp.ui.axutils.childrenAbove(element, bottomElement) -> table of axuielement or nil
TypeFunction
DescriptionFinds the list of axuielement children from the element which are above the specified bottomElement. If the element is nil, nil is returned. If the topElement is nil all children are returned.
Parameters
  • element - The axuielement to find the children of.
  • topElement - The axuielement that the other children must be above.
Returns
  • The table of axuielements that are above, or nil if the element is not available.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 197

Signaturecp.ui.axutils.childrenBelow(element, topElement) -> table of axuielement or nil
TypeFunction
DescriptionFinds the list of axuielement children from the element which are below the specified topElement. If the element is nil, nil is returned. If the topElement is nil all children are returned.
Parameters
  • element - The axuielement to find the children of.
  • topElement - The axuielement that the other children must be below.
Returns
  • The table of axuielements that are below, or nil if the element is not available.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 183

Signaturecp.ui.axutils.childrenInColumn(element, role, startIndex) -> table | nil
TypeFunction
DescriptionFinds the children for an element, then checks to see if they match the supplied role. It then compares the vertical position data of all matching children and returns a table with only the elements that line up to the element defined by the startIndex.
Parameters
  • element - The element to retrieve the children from.
  • role - The required role as a string.
  • startIndex - A number which defines the index of the first element to use.
Returns
  • The table of axuielement objects, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 93

Signaturecp.ui.axutils.childrenInLine(element) -> table | nil
TypeFunction
DescriptionGets a table of children that are all in the same family and line as the supplied element.
Parameters
  • element - The base element.
Returns
  • The table of axuielement objects, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 39

Signaturecp.ui.axutils.childrenInNextLine(element) -> table | nil
TypeFunction
DescriptionGets a table of children that are in the next line in relation to the supplied element. Scrollbars will be ignored.
Parameters
  • element - The base element.
Returns
  • The table of axuielement objects, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 65

Signaturecp.ui.axutils.childrenMatching(element, matcherFn) -> { axuielement }
TypeFunction
DescriptionThis searches for all children of the specified element for which the provided function returns true. The function will receive one parameter - the current child.
Parameters
  • element - the axuielement
  • matcherFn - the function which checks if the child matches the requirements.
Returns
  • All matching children, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 572

Signaturecp.ui.axutils.childrenWith(element, name, value) -> axuielement
TypeFunction
DescriptionThis searches for all children of the specified element which has an attribute with the matching name and value.
Parameters
  • element - the axuielement
  • name - the name of the attribute
  • value - the value of the attribute
Returns
  • All matching children, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 543

Signaturecp.ui.axutils.childrenWithRole(element, value) -> axuielement
TypeFunction
DescriptionThis searches for all children of the specified element which has an AXRole attribute with the matching value.
Parameters
  • element - the axuielement
  • value - the value of the attribute
Returns
  • All matching children, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 558

Signaturecp.ui.axutils.childWith(element, name, value) -> axuielement
TypeFunction
DescriptionThis searches for the first child of the specified element which has an attribute with the matching name and value.
Parameters
  • element - the axuielement
  • name - the name of the attribute
  • value - the value of the attribute
Returns
  • The first matching child, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 283

Signaturecp.ui.axutils.childWithDescription(element, value) -> axuielement
TypeFunction
DescriptionThis searches for the first child of the specified element which has AXDescription with the specified value.
Parameters
  • element - the axuielement
  • value - the value
Returns
  • The first matching child, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 340

Signaturecp.ui.axutils.childWithID(element, value) -> axuielement
TypeFunction
DescriptionThis searches for the first child of the specified element which has AXIdentifier with the specified value.
Parameters
  • element - the axuielement
  • value - the value
Returns
  • The first matching child, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 298

Signaturecp.ui.axutils.childWithRole(element, value) -> axuielement
TypeFunction
DescriptionThis searches for the first child of the specified element which has AXRole with the specified value.
Parameters
  • element - the axuielement
  • value - the value
Returns
  • The first matching child, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 312

Signaturecp.ui.axutils.childWithTitle(element, value) -> axuielement
TypeFunction
DescriptionThis searches for the first child of the specified element which has AXTitle with the specified value.
Parameters
  • element - the axuielement
  • value - the value
Returns
  • The first matching child, or nil if none was found
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 326

Signaturecp.ui.axutils.hasAttributeValue(element, name, value) -> boolean
TypeFunction
DescriptionChecks to see if an element has a specific value.
Parameters
  • element - the axuielement
  • name - the name of the attribute
  • value - the value of the attribute
Returns
  • true if the element has the supplied attribute value, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 211

Signaturecp.ui.axutils.hasChild(element, matcherFn) -> boolean
TypeFunction
DescriptionChecks if the axuielement has a child that passes the matcherFn.
Parameters
  • element - the axuielement to check.
  • matcherFn - the function that accepts an axuielement and returns a boolean
Returns
  • true if any child matches, otherwise false.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 589

Signaturecp.ui.axutils.isValid(element) -> boolean
TypeFunction
DescriptionChecks if the axuilelement is still valid - that is, still active in the UI.
Parameters
  • element - the axuielement
Returns
  • true if the element is valid.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 624

Signaturecp.ui.axutils.prop(uiFinder, attributeName[, settable]) -> cp.prop
TypeFunction
DescriptionCreates a new cp.prop which will find the hs.axuielement via the uiFinder and get/set the value (if settable is true).
Parameters
  • uiFinder - the cp.prop or function which will retrieve the current hs.axuielement.
  • attributeName - the AX atrribute name the property links to.
  • settable - Defaults to false. If true, the property will also be settable.
Returns
  • The cp.prop for the attribute.
Notes
  • If the uiFinder is a cp.prop, it will be monitored for changes, making the resulting prop "live".
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 761

Signaturecp.ui.axutils.snapshot(element, filename, elementFrame) -> hs.image
TypeFunction
DescriptionTakes a snapshot of the specified axuielement and returns it. If the filename is provided it also saves the file to the specified location.
Parameters
  • element - The axuielement to snap.
  • filename - (optional) The path to save the image as a PNG file.
  • elementFrame - (optional) The hs.geometry frame of what you want to capture
Returns
  • An hs.image file, or nil if the element could not be snapped.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 689

Signaturecp.ui.axutils.valueOf(element, name[, default]) -> anything
TypeFunction
DescriptionReturns the named AX attribute value, or the default if it is empty.
Parameters
  • element - the axuielement to retrieve the attribute value for.
  • attribute - The attribute name (e.g. "AXValue")
  • default - (optional) if provided, this will be returned if the attribute is nil.
Returns
  • The attribute value, or the default if none is found.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 22

Signaturecp.ui.axutils.withAttributeValue(element, name, value) -> hs.axuielement | nil
TypeFunction
DescriptionChecks if the element has an attribute value with the specified name and value. If so, the element is returned, otherwise nil.
Parameters
  • element - The element to check
  • name - The name of the attribute to check
  • value - The value of the attribute
Returns
  • The axuielement if it matches, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 226

Signaturecp.ui.axutils.withRole(element, role) -> hs.axuielement | nil
TypeFunction
DescriptionChecks if the element has an "AXRole" attribute with the specified role. If so, the element is returned, otherwise nil.
Parameters
  • element - The element to check
  • role - The required role
Returns
  • The axuielement if it matches, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 241

Signaturecp.ui.axutils.withTitle(element, title) -> hs.axuielement | nil
TypeFunction
DescriptionChecks if the element has an "AXTitle" attribute with the specified title. If so, the element is returned, otherwise nil.
Parameters
  • element - The element to check
  • title - The required title
Returns
  • The axuielement if it matches, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 269

Signaturecp.ui.axutils.withValue(element, value) -> hs.axuielement | nil
TypeFunction
DescriptionChecks if the element has an "AXValue" attribute with the specified value. If so, the element is returned, otherwise nil.
Parameters
  • element - The element to check
  • value - The required value
Returns
  • The axuielement if it matches, otherwise nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/axutils.lua line 255