def getRange(m1, m2): markers = NSArray.alloc().initWithObjects_(m1, m2) return getParameterizedAttributeValue( root, "AXTextMarkerRangeForUnorderedTextMarkers", markers)
def strFromRange(r): return getParameterizedAttributeValue(root, "AXStringForTextMarkerRange", r).encode('utf-8')
def getMarker(index): return getParameterizedAttributeValue(root, "AXTextMarkerForIndex", index)
root = findElem(getRootElement(name=options.app), filter) # print(root) endMarker = getAttributeValue(root, "AXEndTextMarker") nextMarker = getAttributeValue(root, "AXStartTextMarker") startMarker = nextMarker # print(nextMarker) # markers = NSArray.alloc().initWithObjects_(nextMarker, endMarker) # r = getParameterizedAttributeValue(root, "AXTextMarkerRangeForUnorderedTextMarkers", markers) # print(strFromRange(r)) # nextMarker = getMarker(880) i = 0 # nextMarker = getParameterizedAttributeValue(root, "AXNextTextMarkerForTextMarker", nextMarker) while nextMarker: # elem = getParameterizedAttributeValue(root, "AXUIElementForTextMarker", nextMarker) leftWord = strFromRange( getParameterizedAttributeValue( root, "AXLeftWordTextMarkerRangeForTextMarker", nextMarker)) rightWord = strFromRange( getParameterizedAttributeValue( root, "AXRightWordTextMarkerRangeForTextMarker", nextMarker)) print([leftWord, rightWord]) nextMarker = getParameterizedAttributeValue( root, "AXNextTextMarkerForTextMarker", nextMarker)
from common import getRootElement, findWebArea, elementToString, \ getAttributeValue, getParameterizedAttributeValue, \ findElemWithDOMIdentifier from Foundation import NSDictionary, NSArray root = findElemWithDOMIdentifier(getRootElement(name="Safari"), "image_1") print(elementToString(root)) startMarker = getAttributeValue(root, "AXStartTextMarker") endMarker = getAttributeValue(root, "AXEndTextMarker") markers = NSArray.alloc().initWithObjects_(startMarker, endMarker) r = getParameterizedAttributeValue(root, "AXTextMarkerRangeForUnorderedTextMarkers", markers) def strFromRange(r): return getParameterizedAttributeValue(root, "AXStringForTextMarkerRange", r) print(len(strFromRange(r))) # nextMarker = startMarker # index = 0 # while True: # nextMarker = getParameterizedAttributeValue(root, "AXNextTextMarkerForTextMarker", nextMarker) # leftWord = strFromRange(getParameterizedAttributeValue(root, "AXLeftWordTextMarkerRangeForTextMarker", nextMarker)) # rightWord = strFromRange(getParameterizedAttributeValue(root, "AXRightWordTextMarkerRangeForTextMarker", nextMarker)) # print("%d [%s] [%s] " % (index, leftWord, rightWord)) # index += 1 # if not nextMarker or nextMarker == endMarker:
endMarker = getAttributeValue(root, "AXEndTextMarker") nextMarker = getAttributeValue(root, "AXStartTextMarker") startMarker = nextMarker # markers = NSArray.alloc().initWithObjects_(nextMarker, endMarker) # r = getParameterizedAttributeValue(root, "AXTextMarkerRangeForUnorderedTextMarkers", markers) # print(strFromRange(r)) # nextMarker = getMarker(880) expected = [] words = [] elements = [] i = 0 while nextMarker: leftWord = strFromRange( getParameterizedAttributeValue( root, "AXLeftWordTextMarkerRangeForTextMarker", nextMarker)) rightWord = strFromRange( getParameterizedAttributeValue( root, "AXRightWordTextMarkerRangeForTextMarker", nextMarker)) elem = getParameterizedAttributeValue(root, "AXUIElementForTextMarker", nextMarker) d = {} d["words"] = [leftWord, rightWord] d["element"] = [ getAttributeValue(elem, "AXRole"), getAttributeValue(elem, "AXValue") ] d["lines"] = [ strFromRange( getParameterizedAttributeValue( root, "AXLineTextMarkerRangeForTextMarker", nextMarker)),
# root = getAttributeValue(root, "AXChildren")[0] # start_elem = getAttributeValue(root, "AXChildren")[0] print elementToString(root, attributes=kBasicAttributes + ["AXDOMIdentifier"]) print "===" res = [] if options.loop: r = getParameterizedAttributeValue( root, "AXUIElementsForSearchPredicate", { "AXSearchKey": options.search_key, "AXResultsLimit": 1, "AXImmediateDescendantsOnly": options.immediate, "AXDirection": "AXDirectionPrevious" if options.previous else "AXDirectionNext" }) while len(r): res.append(r[0]) r = getParameterizedAttributeValue( root, "AXUIElementsForSearchPredicate", { "AXSearchKey": options.search_key, "AXResultsLimit": 1, "AXImmediateDescendantsOnly": options.immediate,