New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-selection

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-selection

Get current selected text by using system accessibility APIs

  • 0.2.0-alpha.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-7.14%
Maintainers
1
Weekly downloads
 
Created
Source

node-selection

Get current selected text by using system accessibility APIs

Installation

npm i node-selection

Usage

Accessibility permissions

macOS requires accessibility permissions to be granted before a program can control the Mac by using accessibility features.

checkAccessibilityPermissions([options])
  • options: <Object>
    • prompt: <boolean> Default: false

Returns: <Promise> Fullfills upon success with a boolean indicating whether accessibility permissions have been granted to this program.

If prompt is true, a prompt window will be shown when accessibility permissions have not been granted.

If this method is invoked on non-macOS platform, it always returns true.

import { checkAccessibilityPermissions } from 'node-selection';

if (!(await checkAccessibilityPermissions({ prompt: true }))) {
  console.log('grant accessibility permissions and restart this program');
  process.exit(1);
}

Selection

getSelection()

Returns: <Promise> Fullfills upon success with an object with one property:

  • text: <string> | <undefined> Current selected text.
  • process: Object | <undefined>
    • pid: <number> | <undefined> The process ID.
    • name: <string> | <undefined> The filename of the process.
    • bundleIdentifier: <string> | <undefined> The bundle identifier of the process (macOS only).
import { getSelection } from 'node-selection';

try {
  const { text, process } = await getSelection();
  console.log('current selection:', { text, process });
} catch (error) {
  // no valid selection
  console.error('error', error);
}

Examples

  • Node
  • Electron

FAQs

Package last updated on 06 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc