
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
node-selection
Advanced tools
Get current selected text by using system accessibility APIs
npm i node-selection
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: falseReturns: <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);
}
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);
}
FAQs
Get current selected text by using system accessibility APIs
We found that node-selection demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.