Documentation
¶
Overview ¶
Package axuiautomation provides XCUIAutomation-style interfaces for macOS accessibility automation.
This package wraps the macOS Accessibility APIs (AXUIElement, AXObserver, etc.) with a clean, Go-idiomatic interface inspired by Apple's XCUIAutomation framework.
Core Types ¶
- Application: represents a running application
- Element: represents a UI element (button, window, etc.)
- ElementQuery: fluent API for finding elements
- Observer: event-based waiting for UI state changes
Example Usage ¶
app, err := axuiautomation.NewApplication("com.apple.dt.Xcode")
if err != nil {
log.Fatal(err)
}
defer app.Close()
// Find and click a button
replayBtn := app.Windows().Buttons().ByTitle("Replay").Element(0)
if replayBtn.Exists() && replayBtn.IsEnabled() {
replayBtn.Click()
}
// Wait for element with observer
observer, _ := app.NewObserver()
defer observer.Close()
err = observer.WaitForEnabled(replayBtn, 5*time.Minute)
Thread Safety ¶
The macOS Accessibility API must be called from the main thread. Callers should use runtime.LockOSThread in their main goroutine before calling any functions in this package. Observer-based waiting methods spin the CFRunLoop internally, which also requires the main thread.
Memory Ownership ¶
Elements returned from query methods (First, AllElements, Element) are caller-owned and must be released by calling Release when no longer needed. Application.Close releases the root element; callers must still release any elements obtained from queries. Failing to release elements leaks the underlying AXUIElementRef.
Accessibility Permissions ¶
This package requires accessibility permissions. Use IsProcessTrusted() to check if your app has the required permissions.
Index ¶
- Constants
- Variables
- func AXIsProcessTrusted() bool
- func AXIsProcessTrustedWithOptions(options uintptr) bool
- func AXObserverGetRunLoopSource(observer AXObserverRef) uintptr
- func AXValueGetValue(value AXValueRef, valueType AXValueType, valuePtr unsafe.Pointer) bool
- func CheckAccessibilityAccess(pid int32) (int, string)
- func CheckScreenCapture()
- func CheckTrust()
- func CheckTrustWithPrompt()
- func IsProcessTrusted() bool
- func IsScreenRecordingTrusted() bool
- func PromptForAccessibility() bool
- func SendArrowDown() error
- func SendArrowLeft() error
- func SendArrowRight() error
- func SendArrowUp() error
- func SendCmdN() error
- func SendCmdShiftG() error
- func SendDelete() error
- func SendEscape() error
- func SendKeyCombo(keyCode uint16, shift, control, option, command bool) error
- func SendReturn() error
- func SendShiftTab() error
- func SendTab() error
- func SpinMainRunLoop(d time.Duration)
- func SpinRunLoop(d time.Duration)
- func TypeText(text string) error
- type AXError
- func AXObserverAddNotification(observer AXObserverRef, element AXUIElementRef, notification uintptr, ...) AXError
- func AXObserverCreate(pid int32, callback AXObserverCallback, observer *AXObserverRef) AXError
- func AXUIElementCopyAttributeValue(element AXUIElementRef, attribute uintptr, value *uintptr) AXError
- func AXUIElementCopyAttributeValueCF(element AXUIElementRef, attribute uintptr, value *unsafe.Pointer) AXError
- func AXUIElementGetAttributeValueCount(element AXUIElementRef, attribute uintptr, count *int) AXError
- func AXUIElementGetPid(element AXUIElementRef, pid *int32) AXError
- func AXUIElementPerformAction(element AXUIElementRef, action uintptr) AXError
- func AXUIElementSetAttributeValue(element AXUIElementRef, attribute uintptr, value uintptr) AXError
- type AXObserverCallback
- type AXObserverRef
- type AXUIElementRef
- type AXValueRef
- type AXValueType
- type Application
- func (a *Application) Activate() error
- func (a *Application) BundleID() string
- func (a *Application) Buttons() *ElementQuery
- func (a *Application) Checkboxes() *ElementQuery
- func (a *Application) ClickMenuItem(path []string) error
- func (a *Application) Close()
- func (a *Application) Descendants() *ElementQuery
- func (a *Application) Dialogs() *ElementQuery
- func (a *Application) FocusedElement() *Element
- func (a *Application) IsRunning() bool
- func (a *Application) MainWindow() *Element
- func (a *Application) MenuBar() *Element
- func (a *Application) NewObserver() (*Observer, error)
- func (a *Application) PID() int32
- func (a *Application) Root() *Element
- func (a *Application) Sheets() *ElementQuery
- func (a *Application) TextFields() *ElementQuery
- func (a *Application) WaitForWindow(title string, timeout time.Duration) (*Element, error)
- func (a *Application) WindowByTitle(title string) *Element
- func (a *Application) WindowByTitleContains(substr string) *Element
- func (a *Application) WindowList() []*Element
- func (a *Application) Windows() *ElementQuery
- type Element
- func (e *Element) Application() *Application
- func (e *Element) Buttons() *ElementQuery
- func (e *Element) Center() (x, y int)
- func (e *Element) Checkboxes() *ElementQuery
- func (e *Element) ChildCount() int
- func (e *Element) Children() []*Element
- func (e *Element) Click() error
- func (e *Element) ClickAt(xOffset, yOffset int) error
- func (e *Element) Descendants() *ElementQuery
- func (e *Element) Description() string
- func (e *Element) Document() string
- func (e *Element) DoubleClick() error
- func (e *Element) Exists() bool
- func (e *Element) Focus() error
- func (e *Element) Frame() Rect
- func (e *Element) Groups() *ElementQuery
- func (e *Element) Hover() error
- func (e *Element) Identifier() string
- func (e *Element) IntValue() int
- func (e *Element) IsChecked() bool
- func (e *Element) IsEnabled() bool
- func (e *Element) IsFocused() bool
- func (e *Element) IsSelected() bool
- func (e *Element) MenuItems() *ElementQuery
- func (e *Element) Parent() *Element
- func (e *Element) PerformAction(action string) error
- func (e *Element) PopUpButtons() *ElementQuery
- func (e *Element) Position() (x, y int)
- func (e *Element) Raise() error
- func (e *Element) Ref() AXUIElementRef
- func (e *Element) Release()
- func (e *Element) Role() string
- func (e *Element) RoleDescription() string
- func (e *Element) Screenshot() ([]byte, error)
- func (e *Element) Scroll(direction ScrollDirection, lines int) error
- func (e *Element) ScrollAndClick() error
- func (e *Element) ScrollToVisible() error
- func (e *Element) SelectMenuItem(title string) error
- func (e *Element) SelectValue(value string) error
- func (e *Element) SetPosition(x, y float64) error
- func (e *Element) SetValue(value string) error
- func (e *Element) Size() (width, height int)
- func (e *Element) StaticTexts() *ElementQuery
- func (e *Element) Subrole() string
- func (e *Element) TextFields() *ElementQuery
- func (e *Element) Title() string
- func (e *Element) TypeText(text string) error
- func (e *Element) Value() string
- func (e *Element) WaitAndClick(timeout time.Duration) error
- func (e *Element) Windows() *ElementQuery
- type ElementPredicate
- type ElementQuery
- func (q *ElementQuery) AllElements() []*Element
- func (q *ElementQuery) ByDescription(desc string) *ElementQuery
- func (q *ElementQuery) ByIdentifier(id string) *ElementQuery
- func (q *ElementQuery) ByRole(role string) *ElementQuery
- func (q *ElementQuery) ByTitle(title string) *ElementQuery
- func (q *ElementQuery) ByTitleContains(substr string) *ElementQuery
- func (q *ElementQuery) ByTitlePrefix(prefix string) *ElementQuery
- func (q *ElementQuery) ByValue(value string) *ElementQuery
- func (q *ElementQuery) Count() int
- func (q *ElementQuery) Element(index int) *Element
- func (q *ElementQuery) Enabled() *ElementQuery
- func (q *ElementQuery) Exists() bool
- func (q *ElementQuery) First() *Element
- func (q *ElementQuery) Focused() *ElementQuery
- func (q *ElementQuery) ForEach(fn func(*Element) bool)
- func (q *ElementQuery) Matching(pred ElementPredicate) *ElementQuery
- func (q *ElementQuery) Selected() *ElementQuery
- func (q *ElementQuery) WithLimit(n int) *ElementQuery
- func (q *ElementQuery) WithTraversal(mode TraversalMode) *ElementQuery
- type Error
- type Observer
- func (o *Observer) Close()
- func (o *Observer) OnFocusChanged(handler ObserverHandler) error
- func (o *Observer) OnNotification(name string, element *Element, handler ObserverHandler) error
- func (o *Observer) OnUIElementDestroyed(element *Element, handler ObserverHandler) error
- func (o *Observer) OnValueChanged(element *Element, handler ObserverHandler) error
- func (o *Observer) OnWindowCreated(handler ObserverHandler) error
- func (o *Observer) Start()
- func (o *Observer) Stop()
- func (o *Observer) WaitForDisappear(element *Element, timeout time.Duration) error
- func (o *Observer) WaitForElement(query *ElementQuery, timeout time.Duration) (*Element, error)
- func (o *Observer) WaitForEnabled(element *Element, timeout time.Duration) error
- func (o *Observer) WaitForValueChange(element *Element, timeout time.Duration) error
- func (o *Observer) WaitWithCondition(condition func() bool, timeout time.Duration) error
- type ObserverEvent
- type ObserverHandler
- type Point
- type Rect
- type ScrollDirection
- type Size
- type TraversalMode
Examples ¶
Constants ¶
const ( NotificationFocusedUIElementChanged = "AXFocusedUIElementChanged" NotificationValueChanged = "AXValueChanged" NotificationUIElementDestroyed = "AXUIElementDestroyed" NotificationWindowCreated = "AXWindowCreated" NotificationWindowMoved = "AXWindowMoved" NotificationWindowResized = "AXWindowResized" NotificationWindowMiniaturized = "AXWindowMiniaturized" NotificationWindowDeminiaturized = "AXWindowDeminiaturized" NotificationApplicationActivated = "AXApplicationActivated" NotificationApplicationDeactivated = "AXApplicationDeactivated" NotificationApplicationHidden = "AXApplicationHidden" NotificationApplicationShown = "AXApplicationShown" NotificationSelectedChildrenChanged = "AXSelectedChildrenChanged" NotificationSelectedTextChanged = "AXSelectedTextChanged" NotificationTitleChanged = "AXTitleChanged" )
Common AX notification names
Variables ¶
var ( ErrNotRunning = errors.New("application not running") ErrElementNotFound = errors.New("element not found") ErrTimeout = errors.New("operation timed out") ErrAPIDisabled = errors.New("accessibility API disabled") ErrActionUnsupported = errors.New("action not supported") ErrInvalidElement = errors.New("invalid UI element") )
Common errors
Functions ¶
func AXIsProcessTrusted ¶
func AXIsProcessTrusted() bool
func AXObserverGetRunLoopSource ¶
func AXObserverGetRunLoopSource(observer AXObserverRef) uintptr
func AXValueGetValue ¶
func AXValueGetValue(value AXValueRef, valueType AXValueType, valuePtr unsafe.Pointer) bool
func CheckAccessibilityAccess ¶
CheckAccessibilityAccess performs a diagnostic check to see if accessibility API is working. Returns the AX error code (0 = success, -25211 = API disabled/no permission).
func CheckScreenCapture ¶
func CheckScreenCapture()
func CheckTrust ¶
func CheckTrust()
CheckTrust checks if the process has Accessibility permission and, if not, shows a floating window with a spinner and buttons to open System Settings or reset TCC. It polls until permission is granted, then briefly shows a green checkmark before closing.
func CheckTrustWithPrompt ¶
func CheckTrustWithPrompt()
CheckTrustWithPrompt is like CheckTrust but also triggers the system universalAccessAuthWarn permission dialog. Prefer CheckTrust for a less disruptive experience.
func IsProcessTrusted ¶
func IsProcessTrusted() bool
IsProcessTrusted checks if the current process has accessibility permissions.
func IsScreenRecordingTrusted ¶
func IsScreenRecordingTrusted() bool
func PromptForAccessibility ¶
func PromptForAccessibility() bool
PromptForAccessibility triggers the system accessibility permission prompt. Returns true if already trusted, false otherwise.
func SendCmdShiftG ¶
func SendCmdShiftG() error
SendCmdShiftG sends Command+Shift+G (Go to Folder in save dialogs).
func SendKeyCombo ¶
SendKeyCombo sends a key combination with modifiers. Modifiers: shift, control, option, command
func SpinMainRunLoop ¶
SpinMainRunLoop briefly runs the NSRunLoop on the main thread for the given duration. Unlike SpinRunLoop (which only pumps CFRunLoop), this also drains the GCD main queue, so DispatchMainSafe callbacks and AppKit UI events are processed. Must be called from the main OS thread.
func SpinRunLoop ¶
SpinRunLoop briefly spins the current thread's CFRunLoop to allow pending accessibility IPC replies to be delivered. Many AX attributes (notably AXMenuBar) require at least one run-loop iteration to return a value in processes that do not otherwise run a persistent run loop (e.g. CLI tools).
Types ¶
type AXError ¶
type AXError = int32
func AXObserverAddNotification ¶
func AXObserverAddNotification(observer AXObserverRef, element AXUIElementRef, notification uintptr, refcon unsafe.Pointer) AXError
func AXObserverCreate ¶
func AXObserverCreate(pid int32, callback AXObserverCallback, observer *AXObserverRef) AXError
func AXUIElementCopyAttributeValue ¶
func AXUIElementCopyAttributeValue(element AXUIElementRef, attribute uintptr, value *uintptr) AXError
func AXUIElementCopyAttributeValueCF ¶
func AXUIElementCopyAttributeValueCF(element AXUIElementRef, attribute uintptr, value *unsafe.Pointer) AXError
AXUIElementCopyAttributeValueCF is a version that works with CFTypeRef pointers
func AXUIElementGetAttributeValueCount ¶
func AXUIElementGetAttributeValueCount(element AXUIElementRef, attribute uintptr, count *int) AXError
func AXUIElementGetPid ¶
func AXUIElementGetPid(element AXUIElementRef, pid *int32) AXError
func AXUIElementPerformAction ¶
func AXUIElementPerformAction(element AXUIElementRef, action uintptr) AXError
func AXUIElementSetAttributeValue ¶
func AXUIElementSetAttributeValue(element AXUIElementRef, attribute uintptr, value uintptr) AXError
type AXObserverCallback ¶
type AXObserverCallback = uintptr
type AXObserverRef ¶
type AXObserverRef = uintptr
type AXUIElementRef ¶
type AXUIElementRef = uintptr
Type aliases for accessibility types
func AXUIElementCreateApplication ¶
func AXUIElementCreateApplication(pid int32) AXUIElementRef
type AXValueRef ¶
type AXValueRef = uintptr
func AXValueCreate ¶
func AXValueCreate(valueType AXValueType, valuePtr unsafe.Pointer) AXValueRef
type AXValueType ¶
type AXValueType = int32
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application represents a running macOS application for accessibility automation. It holds the root AXUIElementRef for the process and serves as the entry point for element queries and observers. Call Close when done to release the root element and cached resources.
func NewApplication ¶
func NewApplication(bundleID string) (*Application, error)
NewApplication creates a new Application by bundle ID. It looks up the running process by bundle ID and creates an accessibility element for it.
Example ¶
Example tests
package main
import (
"github.com/tmc/apple/x/axuiautomation"
)
func main() {
app, err := axuiautomation.NewApplication("com.apple.finder")
if err != nil {
return
}
defer app.Close()
// Get the first window
window := app.Windows().First()
if window != nil {
_ = window.Title()
}
}
Output:
func NewApplicationFromPID ¶
func NewApplicationFromPID(pid int32) *Application
NewApplicationFromPID creates a new Application from a process ID.
func (*Application) Activate ¶
func (a *Application) Activate() error
Activate brings the application to the foreground.
func (*Application) BundleID ¶
func (a *Application) BundleID() string
BundleID returns the application's bundle ID.
func (*Application) Buttons ¶
func (a *Application) Buttons() *ElementQuery
Buttons returns a query for all buttons in the application.
func (*Application) Checkboxes ¶
func (a *Application) Checkboxes() *ElementQuery
Checkboxes returns a query for all checkboxes in the application.
func (*Application) ClickMenuItem ¶
func (a *Application) ClickMenuItem(path []string) error
ClickMenuItem clicks a menu item by its path (e.g., ["File", "Export..."]).
func (*Application) Close ¶
func (a *Application) Close()
Close releases all resources associated with the application.
func (*Application) Descendants ¶
func (a *Application) Descendants() *ElementQuery
Descendants returns a query for all descendants of the application root.
func (*Application) Dialogs ¶
func (a *Application) Dialogs() *ElementQuery
Dialogs returns a query for all dialog windows.
func (*Application) FocusedElement ¶
func (a *Application) FocusedElement() *Element
FocusedElement returns the currently focused element.
func (*Application) IsRunning ¶
func (a *Application) IsRunning() bool
IsRunning returns true if the application is still running.
func (*Application) MainWindow ¶
func (a *Application) MainWindow() *Element
MainWindow returns the application's main window (first window).
func (*Application) MenuBar ¶
func (a *Application) MenuBar() *Element
MenuBar returns the application's menu bar element. It spins the CFRunLoop briefly on each attempt so that AX IPC replies are delivered even in CLI processes that do not run a persistent event loop.
func (*Application) NewObserver ¶
func (a *Application) NewObserver() (*Observer, error)
NewObserver creates a new observer for this application.
func (*Application) PID ¶
func (a *Application) PID() int32
PID returns the application's process ID.
func (*Application) Root ¶
func (a *Application) Root() *Element
Root returns the root accessibility element for the application.
func (*Application) Sheets ¶
func (a *Application) Sheets() *ElementQuery
Sheets returns a query for all sheet windows.
func (*Application) TextFields ¶
func (a *Application) TextFields() *ElementQuery
TextFields returns a query for all text fields in the application.
func (*Application) WaitForWindow ¶
WaitForWindow waits up to timeout for a window whose title contains the given substring to appear.
func (*Application) WindowByTitle ¶
func (a *Application) WindowByTitle(title string) *Element
WindowByTitle returns the first window with the given title.
func (*Application) WindowByTitleContains ¶
func (a *Application) WindowByTitleContains(substr string) *Element
WindowByTitleContains returns the first window whose title contains the given substring.
func (*Application) WindowList ¶
func (a *Application) WindowList() []*Element
WindowList returns all windows using the AXWindows attribute directly, which is faster and more reliable than traversing AXChildren.
func (*Application) Windows ¶
func (a *Application) Windows() *ElementQuery
Windows returns a query for all windows of the application.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element wraps an AXUIElementRef with Go ownership semantics. Elements obtained from query methods (First, AllElements, Element) are caller-owned and must be released by calling Release. The zero value is not usable; use NewApplication or query methods to obtain elements.
func (*Element) Application ¶
func (e *Element) Application() *Application
Application returns the parent Application for this element.
func (*Element) Buttons ¶
func (e *Element) Buttons() *ElementQuery
Buttons returns a query for button elements.
func (*Element) Checkboxes ¶
func (e *Element) Checkboxes() *ElementQuery
Checkboxes returns a query for checkbox elements.
func (*Element) ChildCount ¶
ChildCount returns the number of children.
func (*Element) Click ¶
Click performs a click on the element. It first tries AXPress, then falls back to CGEvent if AXPress fails.
func (*Element) ClickAt ¶
ClickAt performs a low-level CGEvent click at a specific offset relative to the element's top-left origin.
func (*Element) Descendants ¶
func (e *Element) Descendants() *ElementQuery
Descendants returns a query for all descendants of this element.
func (*Element) Description ¶
Description returns the element's description.
func (*Element) DoubleClick ¶
DoubleClick performs a double-click on the element.
func (*Element) Groups ¶
func (e *Element) Groups() *ElementQuery
Groups returns a query for group elements.
func (*Element) Identifier ¶
Identifier returns the element's unique identifier.
func (*Element) IntValue ¶
IntValue returns the element's value as an integer. Returns 0 if the value is not a number.
func (*Element) IsChecked ¶
IsChecked returns true if the element's value is truthy (for checkboxes/switches).
func (*Element) IsSelected ¶
IsSelected returns true if the element is selected.
func (*Element) MenuItems ¶
func (e *Element) MenuItems() *ElementQuery
MenuItems returns a query for menu item elements.
func (*Element) PerformAction ¶
PerformAction performs a named accessibility action on the element.
func (*Element) PopUpButtons ¶
func (e *Element) PopUpButtons() *ElementQuery
PopUpButtons returns a query for popup button elements.
func (*Element) Ref ¶
func (e *Element) Ref() AXUIElementRef
Ref returns the underlying AXUIElementRef. The caller should not release this ref; it is owned by the Element.
func (*Element) Release ¶
func (e *Element) Release()
Release releases the underlying AXUIElementRef. Callers must call Release on elements returned from query methods (First, AllElements, Element, Parent, Children, FocusedElement, etc.) when the element is no longer needed. After calling Release, the Element must not be used.
func (*Element) Role ¶
Role returns the element's accessibility role (e.g., "AXButton", "AXWindow").
func (*Element) RoleDescription ¶
RoleDescription returns the element's localized role description.
func (*Element) Screenshot ¶
Screenshot captures a PNG of the element's on-screen frame using screencapture. Returns an error if the element has no frame or the capture fails.
func (*Element) Scroll ¶
func (e *Element) Scroll(direction ScrollDirection, lines int) error
Scroll scrolls the element in the given direction by the given number of lines. It first tries the AXScroll action, then falls back to CGEvent scroll wheel.
func (*Element) ScrollAndClick ¶
ScrollAndClick scrolls the element into view and then clicks it.
func (*Element) ScrollToVisible ¶
ScrollToVisible scrolls through ancestor scroll areas until this element is visible. It walks up the tree looking for an AXScrollArea or AXOutline parent and scrolls it.
func (*Element) SelectMenuItem ¶
SelectMenuItem clicks this element (assumed to be an AXPopUpButton or AXComboBox), waits for the menu to open, and clicks the menu item with the given title.
func (*Element) SelectValue ¶
SelectValue sets the value of a combo box or other value-settable element, then tries to select a matching item from a popup if present.
func (*Element) SetPosition ¶
SetPosition moves the element to the specified coordinates.
func (*Element) StaticTexts ¶
func (e *Element) StaticTexts() *ElementQuery
StaticTexts returns a query for static text elements.
func (*Element) TextFields ¶
func (e *Element) TextFields() *ElementQuery
TextFields returns a query for text field elements.
func (*Element) TypeText ¶
TypeText focuses the element and types the given text using keyboard events.
func (*Element) WaitAndClick ¶
WaitAndClick waits up to timeout for the element to exist and be enabled, then clicks it.
func (*Element) Windows ¶
func (e *Element) Windows() *ElementQuery
Windows returns a query for window elements.
type ElementPredicate ¶
ElementPredicate is a function that tests if an element matches criteria.
type ElementQuery ¶
type ElementQuery struct {
// contains filtered or unexported fields
}
ElementQuery provides a fluent builder for finding UI elements by chaining predicates such as ByRole, ByTitle, and Matching. Each filter method returns a new query, leaving the original unmodified. Terminal methods (First, AllElements, Element) execute the search and return caller-owned elements that must be released.
Example ¶
package main
import (
"github.com/tmc/apple/x/axuiautomation"
)
func main() {
app, err := axuiautomation.NewApplication("com.apple.finder")
if err != nil {
return
}
defer app.Close()
// Find all buttons with "OK" in the title
buttons := app.Buttons().ByTitleContains("OK").AllElements()
for _, btn := range buttons {
_ = btn.Title()
}
}
Output:
func (*ElementQuery) AllElements ¶
func (q *ElementQuery) AllElements() []*Element
AllElements returns all matching elements. The returned elements are caller-owned and each must be released.
func (*ElementQuery) ByDescription ¶
func (q *ElementQuery) ByDescription(desc string) *ElementQuery
ByDescription filters elements by their description.
func (*ElementQuery) ByIdentifier ¶
func (q *ElementQuery) ByIdentifier(id string) *ElementQuery
ByIdentifier filters elements by their unique identifier.
func (*ElementQuery) ByRole ¶
func (q *ElementQuery) ByRole(role string) *ElementQuery
ByRole filters elements by their accessibility role.
func (*ElementQuery) ByTitle ¶
func (q *ElementQuery) ByTitle(title string) *ElementQuery
ByTitle filters elements by their title.
func (*ElementQuery) ByTitleContains ¶
func (q *ElementQuery) ByTitleContains(substr string) *ElementQuery
ByTitleContains filters elements whose title contains the given substring.
func (*ElementQuery) ByTitlePrefix ¶
func (q *ElementQuery) ByTitlePrefix(prefix string) *ElementQuery
ByTitlePrefix filters elements whose title starts with the given prefix.
func (*ElementQuery) ByValue ¶
func (q *ElementQuery) ByValue(value string) *ElementQuery
ByValue filters elements by their value.
func (*ElementQuery) Count ¶
func (q *ElementQuery) Count() int
Count returns the number of matching elements.
func (*ElementQuery) Element ¶
func (q *ElementQuery) Element(index int) *Element
Element returns the element at the given index (0 for first match).
func (*ElementQuery) Enabled ¶
func (q *ElementQuery) Enabled() *ElementQuery
Enabled filters to only enabled elements.
func (*ElementQuery) Exists ¶
func (q *ElementQuery) Exists() bool
Exists returns true if at least one matching element exists.
func (*ElementQuery) First ¶
func (q *ElementQuery) First() *Element
First returns the first matching element, or nil if none match. The returned element is caller-owned and must be released.
func (*ElementQuery) Focused ¶
func (q *ElementQuery) Focused() *ElementQuery
Focused filters to only focused elements.
func (*ElementQuery) ForEach ¶
func (q *ElementQuery) ForEach(fn func(*Element) bool)
ForEach calls the given function for each matching element. The function can return false to stop iteration.
func (*ElementQuery) Matching ¶
func (q *ElementQuery) Matching(pred ElementPredicate) *ElementQuery
Matching adds a custom predicate to the query.
func (*ElementQuery) Selected ¶
func (q *ElementQuery) Selected() *ElementQuery
Selected filters to only selected elements.
func (*ElementQuery) WithLimit ¶
func (q *ElementQuery) WithLimit(n int) *ElementQuery
WithLimit sets the maximum number of elements to visit during search.
func (*ElementQuery) WithTraversal ¶
func (q *ElementQuery) WithTraversal(mode TraversalMode) *ElementQuery
WithTraversal sets the traversal mode (BFS or DFS).
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
Observer provides event-based waiting for UI state changes using the AXObserver API. Observer methods spin the CFRunLoop to receive notifications, which requires the caller to be on the main thread (see runtime.LockOSThread). Call Close to release all resources.
func NewObserver ¶
func NewObserver(app *Application) (*Observer, error)
NewObserver creates a new observer for the given application.
func (*Observer) Close ¶
func (o *Observer) Close()
Close releases all resources associated with the observer.
func (*Observer) OnFocusChanged ¶
func (o *Observer) OnFocusChanged(handler ObserverHandler) error
OnFocusChanged registers a handler for focus change notifications.
func (*Observer) OnNotification ¶
func (o *Observer) OnNotification(name string, element *Element, handler ObserverHandler) error
OnNotification registers a handler for a specific notification on an element.
func (*Observer) OnUIElementDestroyed ¶
func (o *Observer) OnUIElementDestroyed(element *Element, handler ObserverHandler) error
OnUIElementDestroyed registers a handler for element destruction notifications.
func (*Observer) OnValueChanged ¶
func (o *Observer) OnValueChanged(element *Element, handler ObserverHandler) error
OnValueChanged registers a handler for value change notifications.
func (*Observer) OnWindowCreated ¶
func (o *Observer) OnWindowCreated(handler ObserverHandler) error
OnWindowCreated registers a handler for window creation notifications.
func (*Observer) Start ¶
func (o *Observer) Start()
Start starts processing events. Call this after registering all handlers.
func (*Observer) WaitForDisappear ¶
WaitForDisappear waits for an element to disappear (no longer exists).
func (*Observer) WaitForElement ¶
WaitForElement waits for an element matching the query to appear.
func (*Observer) WaitForEnabled ¶
WaitForEnabled waits for an element to become enabled.
func (*Observer) WaitForValueChange ¶
WaitForValueChange waits for an element's value to change.
type ObserverEvent ¶
ObserverEvent represents an accessibility notification event.
type ObserverHandler ¶
type ObserverHandler func(event ObserverEvent)
ObserverHandler is a callback function for handling observer events.
type ScrollDirection ¶
type ScrollDirection int
ScrollDirection specifies the direction to scroll.
const ( ScrollUp ScrollDirection = iota ScrollDown ScrollLeft ScrollRight )
type TraversalMode ¶
type TraversalMode int
TraversalMode specifies how to traverse the element tree.
const ( // BFS performs breadth-first search (default). BFS TraversalMode = iota // DFS performs depth-first search. DFS )