osascript-tag
osascript-tag
is a JavaScript template literal tag that executes AppleScript and other OSA languages.
Every time I get a script it's a matter of trying to know what I could do with it. I see colors, imagery. It has to have a smell. It's like falling in love. You can't give a reason why.
— Paul Newman
Installation
To get started, add osascript-tag
to your project:
npm i --save osascript-tag
⚠️ Warning: This package is still in beta and in active development. The API is likely to change in future releases.
Usage
Running AppleScript
const osascript = require('osascript-tag');
async function main() {
try {
const result = await osascript`
tell application "iTunes"
get properties of current track
end tell
`;
console.log(result);
} catch (error) {
console.log(error);
}
}
Running JXA (JavaScript for Automation)
const osascript = require('osascript-tag');
async function main() {
try {
const result = await osascript.jxa({ flags: 's', json: true })`
const app = Application.currentApplication();
app.includeStandardAdditions = true;
const lang = app.chooseFromList(
["applescript", "javascript", "typescript"],
{
withPrompt: "What is your favorite language?",
multipleSelectionsAllowed: true
}
);
lang;
`;
console.log(result);
} catch (error) {
console.log(error);
}
}
API
Licence
MIT