{"id":13901248,"url":"https://github.com/yetone/get-selected-text","last_synced_at":"2025-04-08T14:10:23.604Z","repository":{"id":237893208,"uuid":"795433004","full_name":"yetone/get-selected-text","owner":"yetone","description":"A tiny Rust library that allows you to easily obtain selected text across all platforms (macOS, Windows, Linux).","archived":false,"fork":false,"pushed_at":"2024-10-09T16:29:42.000Z","size":29,"stargazers_count":166,"open_issues_count":3,"forks_count":15,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T16:48:58.250Z","etag":null,"topics":["rust","selected-text"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yetone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-03T09:15:17.000Z","updated_at":"2025-04-03T12:31:57.000Z","dependencies_parsed_at":"2024-10-25T18:03:43.241Z","dependency_job_id":"deba70d8-67c0-44e2-ab83-2d865dd1b657","html_url":"https://github.com/yetone/get-selected-text","commit_stats":null,"previous_names":["yetone/get-selected-text"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Fget-selected-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Fget-selected-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Fget-selected-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Fget-selected-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yetone","download_url":"https://codeload.github.com/yetone/get-selected-text/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247856544,"owners_count":21007621,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","selected-text"],"created_at":"2024-08-06T21:01:04.512Z","updated_at":"2025-04-08T14:10:23.587Z","avatar_url":"https://github.com/yetone.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"get-selected-text\n=================\n\n[![Lint](https://github.com/yetone/get-selected-text/actions/workflows/lint.yaml/badge.svg)](https://github.com/yetone/get-selected-text/actions/workflows/lint.yaml) [![crates.io](https://img.shields.io/crates/v/get-selected-text.svg)](https://crates.io/crates/get-selected-text)\n\nA tiny Rust library that allows you to easily obtain selected text across all platforms (macOS, Windows, Linux).\n\nCorresponding Node.js package: [node-get-selected-text](https://github.com/yetone/node-get-selected-text)\n\n## Usage\n\n### Add:\n\n```bash\ncargo add get-selected-text\n```\n\n### Use:\n\n```rust\nuse get_selected_text::get_selected_text;\n\nfn main() {\n    match get_selected_text() {\n        Ok(selected_text) =\u003e {\n            println!(\"selected text: {}\", selected_text);\n        },\n        Err(()) =\u003e {\n            println!(\"error occurred while getting the selected text\");\n        }\n    }\n}\n```\n\n## How does it work?\n\n### macOS\n\nPrioritize 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.\n\nTo avoid annoying Alert sounds when simulating pressing cmd+c, it will automatically mute the Alert sound (Only the Alert sound is muted, it won't affect the volume of listening to music and watching videos). The volume of the Alert sound will be restored after releasing the key.\n\nTherefore, on macOS, you need to grant accessbility permissions in advance. The sample code is as follows:\n\n```rust\nfn query_accessibility_permissions() -\u003e bool {\n    let trusted = macos_accessibility_client::accessibility::application_is_trusted_with_prompt();\n    if trusted {\n        print!(\"Application is totally trusted!\");\n    } else {\n        print!(\"Application isn't trusted :(\");\n    }\n    trusted\n}\n```\n\n### Windows + Linux\n\nSimulate pressing ctrl+c to use the clipboard to obtain the selected text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetone%2Fget-selected-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyetone%2Fget-selected-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetone%2Fget-selected-text/lists"}