node-on-selected-text
v0.1.0
Published
Node.js bindings for on-selected-text
Maintainers
Readme
node-on-selected-text
Node.js bindings for on-selected-text, a small native library for reading the currently selected text on macOS, Windows, and Linux.
Source: https://github.com/uxiew/on-selected-text/tree/main/bindings/node
Install
npm install node-on-selected-textThe package is distributed as a small JavaScript loader plus platform-specific optional native packages. npm installs only the binding that matches the current os / cpu / Linux libc; the root package does not ship every .node binary.
Usage
const { checkPermissions, getSelectedText, startSelectionDaemon } = require('node-on-selected-text')
console.log(checkPermissions())
const selection = await getSelectedText({ fetchBounds: true })
console.log(selection.text, selection.bounds)
const daemon = startSelectionDaemon(
{ triggerDelayMs: 120, getTextOptions: { fetchBounds: true } },
(error, nextSelection) => {
if (error) {
console.error(error)
return
}
console.log(nextSelection.text, nextSelection.bounds)
},
)
// Stop the background listener when your app exits.
daemon.stop()Permissions
On macOS, the host process needs Accessibility permission. Call checkPermissions() during startup and guide the user to grant permission when it returns denied.
Smoke test
node -e "require('node-on-selected-text'); console.log('loaded')"For development in this repository, see docs/RELEASE.md and docs/NODE_DISTRIBUTION.md.
