This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
/**
Run AppleScript asynchronously.
@param script - The script to run.
@returns The script result.
@example
```
import {runAppleScriptAsync} from 'run-applescript';
const result = await runAppleScriptAsync('return "unicorn"');
console.log(result);
//=> 'unicorn'
```
*/
export function runAppleScriptAsync(script: string): Promise<string>;
/**
Run AppleScript synchronously.
@param script - The script to run.
@returns The script result.
@example
```
import {runAppleScriptSync} from 'run-applescript';
const result = runAppleScriptSync('return "unicorn"');
console.log(result);
//=> 'unicorn'
```
*/
export function runAppleScriptSync(script: string): string;
+19
View File
@@ -0,0 +1,19 @@
import execa from 'execa';
export async function runAppleScriptAsync(script) {
if (process.platform !== 'darwin') {
throw new Error('macOS only');
}
const {stdout} = await execa('osascript', ['-e', script]);
return stdout;
}
export function runAppleScriptSync(script) {
if (process.platform !== 'darwin') {
throw new Error('macOS only');
}
const {stdout} = execa.sync('osascript', ['-e', script]);
return stdout;
}
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+41
View File
@@ -0,0 +1,41 @@
{
"name": "run-applescript",
"version": "5.0.0",
"description": "Run AppleScript and get the result",
"license": "MIT",
"repository": "sindresorhus/run-applescript",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"macos",
"mac",
"applescript",
"osascript",
"run",
"execute"
],
"dependencies": {
"execa": "^5.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
+34
View File
@@ -0,0 +1,34 @@
# run-applescript
> Run AppleScript and get the result
## Install
```
$ npm install run-applescript
```
## Usage
```js
import {runAppleScriptAsync} from 'run-applescript';
const result = await runAppleScriptAsync('return "unicorn"');
console.log(result);
//=> 'unicorn'
```
## API
### runAppleScriptAsync(script)
Returns a `Promise<string>` with the script result.
### runAppleScriptSync(script)
Returns a `string` with the script result.
## Related
- [run-jxa](https://github.com/sindresorhus/run-jxa) - Run JXA code and get the result