Skip to content

AXPosition: Attempting to query position of text cursor in given text field returns top-left location #24

@kwvg

Description

@kwvg

Example of Text Cursor Location

Hello! I've been interested in Hammerspoon but my knowledge of its APIs (and by extension of AXUIElement) is extremely limited. I've tried to piece together a small script that finds the text cursor location of an active textbox and then overlays information over it (right now it's just right-clicking)

Expected Behavior

AXPosition should return the X,Y coordinates of a text cursor in the active text box

Expected Simulated Behaviour

Actual Behaviour

AXPosition returns the X,Y coordinates of the top left extreme of the active text box

Actual Behaviour

Code used:

local ax = require("hs.axuielement")
hs.hotkey.bindSpec(
    {{ "ctrl", "alt" }, "/"},
    function()
        local currentApp = hs.application.frontmostApplication()
        local axApp = ax.applicationElement(currentApp)
        axApp:setAttributeValue('AXEnhancedUserInterface', true)
        axApp:setAttributeValue('AXManualAccessibility', true)

        local systemElement = ax.systemWideElement()
        local currentElement = systemElement:attributeValue("AXFocusedUIElement")
        hs.eventtap.rightClick(currentElement:attributeValue("AXPosition"))
    end
)

Resources

For the code snippet written above

System Information

macOS Catalina 10.15.7 (19H114)
AXUIElement: Version 1.0.8
Hammerspoon: Version 0.9.82 (5614)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions