How to find cursor position of a currently focused text editable element on Mac OS X?

578 views Asked by At

I need to perform the following task on Mac OS X:

  1. Find an application window that user is currently working in

  2. Find a currently focused element within it

  3. If the element is text editable, find current cursor position

I'd like to use ATOMac, but I cannot figure out how to do this, i.e. what are correct attributes etc. Any ideas?

1

There are 1 answers

0
Dalen On BEST ANSWER
from atomac import getFrontMostApp

def GetInsertionPoint ():
    try: app = getFrontmostApp()
    except: return -1
    for element in app.textFieldsR()+app.textAreasR():
        if element.AXFocused:
            return element.AXSelectedTextRange[0]
    return -1