get-selected-text
A tiny Rust library that allows you to easily obtain selected text across all platforms (macOS, Windows, Linux).
Usage
Add:
Use:
use get_selected_text;
How does it work?
macOS
Prioritize using the A11y API to obtain selected text. If the application does not comply with the A11y API, simulate pressing cmd+c to borrow from the clipboard to get the selected text.
To avoid annoying alert sounds when simulating pressing cmd+c, it will automatically mute the alert sound. The volume of the alert sound will be restored after releasing the key.
Therefore, on macOS, you need to grant accessbility permissions in advance. The sample code is as follows:
Windows + Linux
Simulate pressing ctrl+c to use the clipboard to obtain the selected text.