#cp.ui.notifier

Supports long-lived 'AX' notifiers. Configure the application to watch, the function that provides the axuielement and then register for the type of notification to watch, along with a function that will get triggered.

For example:

local notifier = require("cp.ui.notifier") local function finder() ... end -- returns the axuielement local o = notifier.new("com.apple.FinalCut", finder) o:watchFor("AXValueChanged", function(notifier, element, notification, details) ... end) o:start()

#API Overview

Functions - API calls offered directly by the extension

Constructors - API calls which return an object, typically one that offers API methods

Methods - API calls which can only be made on an object returned by a constructor


#API Documentation

#Functions

Signaturecp.ui.notifier.notifiersForBundleID(bundleID) -> table of cp.ui.notifier
TypeFunction
DescriptionReturns the list of cp.ui.notifier instances that have been created for the specified Bundle ID.
Parameters
  • bundleID - The application Bundle ID being observed. E.g. "com.apple.FinalCut".
Returns
  • A table of cp.ui.notifier instances.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 160

#Constructors

Signaturecp.ui.notifier.new(bundleID, elementFinderFn) -> cp.ui.notifier
TypeConstructor
DescriptionCreates a new cp.ui.notifier instance with the specified bundle ID and a function that returns the element being observed.
Parameters
  • bundleID - The application Bundle ID being observed. E.g. "com.apple.FinalCut".
  • elementFinderFn - The function that will return the axuielement to observe.
Returns
  • A new cp.ui.notifier instance.
Notes
  • The function has a signature of function() -> hs.axuielement.
  • It simply returns the current element being observed, or nil if none is available.
  • The function will be called multiple times over the life of the notifier.
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 126

#Methods

Signaturecp.ui.notifier:app() -> hs.application
TypeMethod
DescriptionReturns the current hs.application instance for the app this notifier tracks. May be nil if the application is not running.
Parameters
  • None
Returns
  • The running hs.application for the notifier's bundleID, or nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 294

Signaturecp.ui.notifier:bundleID()
TypeMethod
DescriptionReturns the application 'bundle ID' that this notifier is tracking.
Parameters
  • None
Returns
  • The application 'bundle ID' string (e.g. "com.apple.FinalCut")
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 281

Signaturecp.ui.notifier:currentElement() -> hs.axuielement
TypeMethod
DescriptionReturns the current axuielement being observed.
Parameters
  • None
Returns
  • The axuielement, or nil if not available.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 173

Signaturecp.ui.notifier:debugging([enabled]) -> boolean
TypeMethod
DescriptionEnables/disables and reports current debugging status. When enabled, a message will be output for each known notification received.
Parameters
  • enabled - If true, debugging notifications will be emitted. If false, it will be disabled. If not provided, no change is made.
Returns
  • true if currently debugging, false otherwise.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 619

Signaturecp.ui.notifier:pid() -> number
TypeMethod
DescriptionReturns the PID for the application being observed, or nil if it's not running.
Parameters
  • None
Returns
  • The PID, or nil.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 329

Signaturecp.ui.notifier:reset() -> self
TypeMethod
DescriptionResets the notifier
Parameters
  • None
Returns
  • Self
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 581

Signaturecp.ui.notifier:start() -> self
TypeMethod
DescriptionStops notifying watchers when events happen.
Parameters
  • None
Returns
  • The cp.ui.notifier instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 564

Signaturecp.ui.notifier:update([force]) -> self
TypeMethod
DescriptionUpdates any watchers to use the current axuielement.
Parameters
  • force - If true, the notifier will be updated even if the element has not changed since the last update. Defaults to false.
Returns
  • The cp.ui.notifier instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 489

Signaturecp.ui.notifier:watchAll(callbackFn) -> self
TypeMethod
DescriptionRegisters the callback as a watcher for all standard notifications for the current axuielement.
Parameters
  • callbackFn - the function to call when the notification happens.
Returns
  • The cp.ui.notifier instance.
Notes
  • This should generally just be used for debugging purposes. It's best to use watchFor[#watchFor] in most cases.
  • The callback function should expect 3 arguments and return none. The arguments passed to the callback will be as follows:
  • the hs.axuielement object for the accessibility element which generated the notification.
  • a string with the notification type.
  • A table containing key-value pairs with more information about the notification, if provided. Commonly this will be an empty table.
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 234

Signaturecp.ui.notifier:watchFor(notification, callbackFn) -> self
TypeMethod
DescriptionRegisters a function to get called whenever the specified notification type is triggered for the current axuielement.
Parameters
  • notifications - The string or table of strings with the notification type(s) to watch for (e.g. "AXValueChanged").
  • callbackFn - The function to call when the matching notification is happens.
Returns
  • The cp.ui.notifier instance.
Notes
  • The callback function should expect 3 arguments and return none. The arguments passed to the callback will be as follows:
  • the hs.axuielement object for the accessibility element which generated the notification.
  • a string with the notification type.
  • A table containing key-value pairs with more information about the notification, if provided. Commonly this will be an empty table.
ExamplesNone
Sourcesrc/extensions/cp/ui/notifier.lua line 186