How to get highlighted text from apps like Mail.app in macOS
up vote
0
down vote
favorite
Below is a snippet that prints highlighted text, however, it does not work with all apps. For instance, one app I know it does not work with is Mail.
What attributes should I be searching for to get the highlighted text in apps like Mail :)
func getHighlightedText() -> AnyObject? {
let systemWideElement = AXUIElementCreateSystemWide()
var focusedElement: AnyObject?
let focusedCode = AXUIElementCopyAttributeValue(systemWideElement, "AXFocusedUIElement" as CFString, &focusedElement)
if (focusedCode == AXError.success) {
var selectedText: AnyObject?
let textCode = AXUIElementCopyAttributeValue(focusedElement as! AXUIElement, "AXSelectedText" as CFString, &selectedText)
if (textCode == AXError.success) {
return selectedText
}
}
return nil
}
sleep(3) #enough time to switch to another app and highlight the text
print(getHighlightedText())
swift macos accessibility
New contributor
add a comment |
up vote
0
down vote
favorite
Below is a snippet that prints highlighted text, however, it does not work with all apps. For instance, one app I know it does not work with is Mail.
What attributes should I be searching for to get the highlighted text in apps like Mail :)
func getHighlightedText() -> AnyObject? {
let systemWideElement = AXUIElementCreateSystemWide()
var focusedElement: AnyObject?
let focusedCode = AXUIElementCopyAttributeValue(systemWideElement, "AXFocusedUIElement" as CFString, &focusedElement)
if (focusedCode == AXError.success) {
var selectedText: AnyObject?
let textCode = AXUIElementCopyAttributeValue(focusedElement as! AXUIElement, "AXSelectedText" as CFString, &selectedText)
if (textCode == AXError.success) {
return selectedText
}
}
return nil
}
sleep(3) #enough time to switch to another app and highlight the text
print(getHighlightedText())
swift macos accessibility
New contributor
Possible duplicate of macOS accessibility API on WebKit applications with AXTextMarker
– Willeke
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Below is a snippet that prints highlighted text, however, it does not work with all apps. For instance, one app I know it does not work with is Mail.
What attributes should I be searching for to get the highlighted text in apps like Mail :)
func getHighlightedText() -> AnyObject? {
let systemWideElement = AXUIElementCreateSystemWide()
var focusedElement: AnyObject?
let focusedCode = AXUIElementCopyAttributeValue(systemWideElement, "AXFocusedUIElement" as CFString, &focusedElement)
if (focusedCode == AXError.success) {
var selectedText: AnyObject?
let textCode = AXUIElementCopyAttributeValue(focusedElement as! AXUIElement, "AXSelectedText" as CFString, &selectedText)
if (textCode == AXError.success) {
return selectedText
}
}
return nil
}
sleep(3) #enough time to switch to another app and highlight the text
print(getHighlightedText())
swift macos accessibility
New contributor
Below is a snippet that prints highlighted text, however, it does not work with all apps. For instance, one app I know it does not work with is Mail.
What attributes should I be searching for to get the highlighted text in apps like Mail :)
func getHighlightedText() -> AnyObject? {
let systemWideElement = AXUIElementCreateSystemWide()
var focusedElement: AnyObject?
let focusedCode = AXUIElementCopyAttributeValue(systemWideElement, "AXFocusedUIElement" as CFString, &focusedElement)
if (focusedCode == AXError.success) {
var selectedText: AnyObject?
let textCode = AXUIElementCopyAttributeValue(focusedElement as! AXUIElement, "AXSelectedText" as CFString, &selectedText)
if (textCode == AXError.success) {
return selectedText
}
}
return nil
}
sleep(3) #enough time to switch to another app and highlight the text
print(getHighlightedText())
swift macos accessibility
swift macos accessibility
New contributor
New contributor
New contributor
asked 2 days ago
HarsilSPatel
111
111
New contributor
New contributor
Possible duplicate of macOS accessibility API on WebKit applications with AXTextMarker
– Willeke
yesterday
add a comment |
Possible duplicate of macOS accessibility API on WebKit applications with AXTextMarker
– Willeke
yesterday
Possible duplicate of macOS accessibility API on WebKit applications with AXTextMarker
– Willeke
yesterday
Possible duplicate of macOS accessibility API on WebKit applications with AXTextMarker
– Willeke
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
HarsilSPatel is a new contributor. Be nice, and check out our Code of Conduct.
HarsilSPatel is a new contributor. Be nice, and check out our Code of Conduct.
HarsilSPatel is a new contributor. Be nice, and check out our Code of Conduct.
HarsilSPatel is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343665%2fhow-to-get-highlighted-text-from-apps-like-mail-app-in-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of macOS accessibility API on WebKit applications with AXTextMarker
– Willeke
yesterday