
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
node-selection
Advanced tools
Get current selected text by using system accessibility APIs
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: 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);
}
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
The npm package node-selection receives a total of 44 weekly downloads. As such, node-selection popularity was classified as not popular.
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.