{"library":"node-osascript","title":"AppleScript Execution from Node.js","description":"node-osascript is a utility library for Node.js that enables the execution of AppleScript code directly from JavaScript. It facilitates bidirectional communication by allowing JavaScript variables to be injected into AppleScript and by transforming AppleScript results (lists, records, dates, numbers, booleans, strings) into their corresponding JavaScript data types using PEG.js. The current stable version is 2.1.0, last published over 8 years ago. While the release cadence is not explicitly stated, the project appears to be in a maintenance or abandoned phase given its age. Its key differentiator is the automatic, structured type conversion of AppleScript results into native JavaScript objects, simplifying data handling compared to raw `exec` calls, which typically return plain strings.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install node-osascript"],"cli":null},"imports":["import osascript from 'node-osascript';","const osascript = require('node-osascript');\nosascript.execute('...', (err, result) => { /* ... */ });","const osascript = require('node-osascript');\nosascript.executeFile('path/to/script.scpt', (err, result) => { /* ... */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import osascript from 'node-osascript';\n\nasync function runAppleScriptWithVariables() {\n  const username = process.env.USER ?? 'Guest';\n  const message = `Hello, ${username}! The current time is now:`;\n  const script = `\n    on run {message}\n      set currentTime to (current date) as text\n      display dialog (message & \"\\n\" & currentTime) with title \"Node-osascript Demo\" buttons {\"OK\"} default button \"OK\"\n      set dialogResult to result\n      return \"User clicked \" & (button returned of dialogResult) & \". Script completed at \" & currentTime\n    end run\n  `;\n\n  try {\n    console.log(`Executing AppleScript on behalf of ${username}...`);\n    const [result, raw] = await new Promise((resolve, reject) => {\n      osascript.execute(script, { message }, (err, res, rawRes) => {\n        if (err) return reject(err);\n        resolve([res, rawRes]);\n      });\n    });\n    console.log(\"Parsed Result:\", result); // e.g., \"User clicked OK. Script completed at...\"\n    console.log(\"Raw AppleScript Output:\", raw); // Full stdout from osascript\n  } catch (error) {\n    console.error(\"AppleScript execution failed:\", error);\n    if (error.code === 1) {\n      console.error(\"Hint: This often means a syntax error in your AppleScript or a permission issue.\");\n    }\n  }\n}\n\nrunAppleScriptWithVariables();","lang":"javascript","description":"Demonstrates executing AppleScript with dynamically injected JavaScript variables, handling asynchronous results, and basic error trapping. This showcases the core `execute` method and variable passing.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}