osascript-tag
Version:
A JavaScript template literal tag that executes OSA scripts (AppleScript, JavaScript, etc.)
48 lines (47 loc) • 1.71 kB
TypeScript
declare type Language = 'AppleScript' | 'JavaScript';
interface SharedOptions {
/**
* Modify the output style. The flags argument is a string consisting of any
* of the modifier characters e, h, o, and s. Multiple modifiers can be
* concatenated in the same string.
*
* The meanings of the modifier characters are as follows:
* - (h) Return values in human-readable form (default).
* - (s) Return values in recompilable source form.
* - (e) Redirect script errors to stderr (default)
* - (o) Redirect script errors to stdout.
*/
flags?: string;
}
interface Options extends SharedOptions {
/**
* Override the language for any plain text files. Normally, plain
* text files are compiled as AppleScript.
*/
language?: Language;
}
interface JXAOptions extends SharedOptions {
/**
* Parse the output result as JSON
*/
parse?: boolean;
/**
* The arguments to pass to the JXA script
*/
argv?: any[];
}
interface TemplateStringFn<T> {
(strings: TemplateStringsArray, ...values: any[]): Promise<T>;
}
declare function osascript<T extends any = any>(script: TemplateStringsArray, ...replacements: any[]): Promise<T>;
declare namespace osascript {
var jxa: typeof execJXA;
}
declare function osascript<T extends any = any>(options: Options): TemplateStringFn<T>;
declare namespace osascript {
var jxa: typeof execJXA;
}
declare function execJXA<T extends any = any>(script: TemplateStringsArray, ...replacements: any[]): Promise<T>;
declare function execJXA<T extends any = any>(options: JXAOptions): TemplateStringFn<T>;
export declare const jxa: typeof execJXA;
export default osascript;