是否可以在 TextEdit 中选择(突出显示)一系列文本(通过 AppleScript、Cocoa 或 Carbon)?我尝试了这段代码但没有用:
set value of attribute "AXSelectedTextRange" to {selStart, selLen}
看来这个属性是只读的。谢谢。
是否可以在 TextEdit 中选择(突出显示)一系列文本(通过 AppleScript、Cocoa 或 Carbon)?我尝试了这段代码但没有用:
set value of attribute "AXSelectedTextRange" to {selStart, selLen}
看来这个属性是只读的。谢谢。
Not sure how to do it with AppleScript (should be possible though), with the accessibility APIs, you could do something like this:
AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();
AXUIElementRef focussedElement = NULL;
AXError error = AXUIElementCopyAttributeValue(systemWideElement, kAXFocusedUIElementAttribute, (CFTypeRef *)&focussedElement);
CFRange range = CFRangeMake(0, 10);
AXUIElementSetAttributeValue(focussedElement, kAXSelectedTextRangeAttribute, AXValueCreate(kAXValueCFRangeType, &range));
CFRelease(focussedElement);
CFRelease(systemWideElement);
That would select the first 10 characters if the TextEdit window is focussed.