run-applescript
Advanced tools
Comparing version 6.0.0 to 6.1.0
@@ -0,1 +1,22 @@ | ||
export type Options = { | ||
/** | ||
Change the output style. | ||
When `false`, returns the value in a [recompilable source form](https://ss64.com/osx/osascript.html). | ||
@default true | ||
@example | ||
``` | ||
import {runAppleScript} from 'run-applescript'; | ||
const result = await runAppleScript('return "unicorn"', {humanReadableOutput: false}); | ||
console.log(result); | ||
//=> '"unicorn"' | ||
``` | ||
*/ | ||
readonly humanReadableOutput?: boolean; | ||
}; | ||
/** | ||
@@ -17,3 +38,6 @@ Run AppleScript asynchronously. | ||
*/ | ||
export function runAppleScript(script: string): Promise<string>; | ||
export function runAppleScript( | ||
script: string, | ||
options?: Options | ||
): Promise<string>; | ||
@@ -36,2 +60,2 @@ /** | ||
*/ | ||
export function runAppleScriptSync(script: string): string; | ||
export function runAppleScriptSync(script: string, options?: Options): string; |
12
index.js
import process from 'node:process'; | ||
import execa from 'execa'; | ||
export async function runAppleScript(script) { | ||
export async function runAppleScript(script, {humanReadableOutput = true} = {}) { | ||
if (process.platform !== 'darwin') { | ||
@@ -9,7 +9,9 @@ throw new Error('macOS only'); | ||
const {stdout} = await execa('osascript', ['-e', script]); | ||
const outputArguments = humanReadableOutput ? [] : ['-ss']; | ||
const {stdout} = await execa('osascript', ['-e', script, outputArguments]); | ||
return stdout; | ||
} | ||
export function runAppleScriptSync(script) { | ||
export function runAppleScriptSync(script, {humanReadableOutput = true} = {}) { | ||
if (process.platform !== 'darwin') { | ||
@@ -19,4 +21,6 @@ throw new Error('macOS only'); | ||
const {stdout} = execa.sync('osascript', ['-e', script]); | ||
const outputArguments = humanReadableOutput ? [] : ['-ss']; | ||
const {stdout} = execa.sync('osascript', ['-e', script, ...outputArguments]); | ||
return stdout; | ||
} |
{ | ||
"name": "run-applescript", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Run AppleScript and get the result", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -24,12 +24,50 @@ # run-applescript | ||
### runAppleScript(script) | ||
### runAppleScript(script, options?) | ||
Returns a `Promise<string>` with the script result. | ||
### runAppleScriptSync(script) | ||
#### script | ||
Type: `string` | ||
The script to run. | ||
#### options | ||
Type: `object` | ||
##### humanReadableOutput | ||
Type: `boolean`\ | ||
Default: `true` | ||
Change the output style. | ||
When `false`, returns the value in a [recompilable source form](https://ss64.com/osx/osascript.html). | ||
### runAppleScriptSync(script, options?) | ||
Returns a `string` with the script result. | ||
#### script | ||
Type: `string` | ||
The script to run. | ||
#### options | ||
Type: `object` | ||
##### humanReadableOutput | ||
Type: `boolean`\ | ||
Default: `true` | ||
Change the output style. | ||
When `false`, returns the value in a [recompilable source form](https://ss64.com/osx/osascript.html). | ||
## Related | ||
- [run-jxa](https://github.com/sindresorhus/run-jxa) - Run JXA code and get the result |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4761
62
73