Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
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 run-applescript
const runApplescript = require('run-applescript');
(async () => {
const result = await runApplescript('return "unicorn"');
console.log(result);
//=> 'unicorn'
})();
Returns a Promise<string>
with the script result.
Returns a string
with the script result.
FAQs
Run AppleScript and get the result
The npm package run-applescript receives a total of 4,277,173 weekly downloads. As such, run-applescript popularity was classified as popular.
We found that run-applescript 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.