
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
run-applescript
Advanced tools
The run-applescript npm package allows Node.js applications to execute AppleScript code directly from JavaScript. This enables developers to automate tasks on macOS, interact with the system and applications in a more integrated manner, and leverage the full power of AppleScript without leaving the Node.js environment.
Executing simple AppleScript commands
This feature allows you to execute straightforward AppleScript commands. The example provided opens a new Finder window on macOS.
const runApplescript = require('run-applescript');
runApplescript('tell app "Finder" to make new Finder window').then(() => {
console.log('Finder window opened.');
});
Getting output from AppleScript
This feature enables the execution of AppleScript commands that return output. The example demonstrates how to get the current volume settings.
const runApplescript = require('run-applescript');
runApplescript('get volume settings').then((output) => {
console.log(output);
});
Handling errors in AppleScript execution
This feature is crucial for robust error handling in your application. It allows you to catch and handle errors that occur during the execution of AppleScript commands. The example tries to execute an invalid command, which results in an error.
const runApplescript = require('run-applescript');
runApplescript('invalid command').catch((error) => {
console.error('AppleScript Error:', error);
});
Similar to run-applescript, the osascript package allows for the execution of AppleScript and JavaScript for Automation (JXA) scripts from Node.js. It provides a similar interface but also supports executing JXA scripts, offering a broader range of scripting capabilities on macOS.
This package also enables the execution of AppleScript from Node.js applications. It is similar to run-applescript but differs in its API and the way it handles script execution and output. node-osascript might offer alternative approaches or additional options for script execution that run-applescript does not.
Run AppleScript and get the result
$ npm install --save run-applescript
const runApplescript = require('run-applescript');
runApplescript('return "unicorn"').then(result => {
console.log(result);
//=> 'unicorn'
});
MIT © Sindre Sorhus
FAQs
Run AppleScript and get the result
The npm package run-applescript receives a total of 5,817,882 weekly downloads. As such, run-applescript popularity was classified as popular.
We found that run-applescript demonstrated a not healthy version release cadence and project activity because the last version was released 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.