How to get global screen coordinates of currently selected text via Accessibility APIs.

You can use the accessibility APIs for that. Make sure that the “Enable access for assistive devices” setting is checked (in System Preferences / Universal Access). The following code snippet will determine the bounds (in screen coordinates) of the selected text in most applications. Unfortunately, it doesn’t work in Mail and Safari, because they use … Read more

How to get selected text from a textbox control with JavaScript

OK, here is the code I have: function ShowSelection() { var textComponent = document.getElementById(‘Editor’); var selectedText; if (textComponent.selectionStart !== undefined) { // Standards-compliant version var startPos = textComponent.selectionStart; var endPos = textComponent.selectionEnd; selectedText = textComponent.value.substring(startPos, endPos); } else if (document.selection !== undefined) { // Internet Explorer version textComponent.focus(); var sel = document.selection.createRange(); selectedText = sel.text; … Read more