Drafts Script Reference
    Preparing search index...

    Class ShellScript

    macOS only. Requires Drafts 19 or greater.

    ShellScript objects can be used to execute Unix shell scripts.

    // define text of bash script
    let script = `#!/bin/bash
    echo "Total arguments : $#"
    echo "1st Argument = $1"
    echo "2nd argument = $2"
    `;
    let runner = ShellScript.create(script);

    if (runner.execute(["1", "2"])) {
    alert("STDOUT: " + runner.standardOutput);
    }
    else {
    alert("STDERR: " + runner.standardError);
    }
    let script = `#!/usr/bin/env ruby
    ARGV.each do |a|
    puts "Argument: #{a}"
    end
    `;
    let runner = ShellScript.create(script);

    if (runner.execute(["1", "2"])) {
    alert("STDOUT:\n" + runner.standardOutput);
    }
    else {
    alert("STDERR:\n" + runner.standardError);
    }

    Note: When executed, scripts are saved to temporary files in the Drafts' script directory at ~/Library/Application Scripts/com.agiletortoise.Drafts-OSX and run. Scripts should not be written to make assumptions about their location in the file system (e.g. using relative paths). The first time a script is executed, the user will be asked to grant permissions to the script directory.

    Index

    Constructors

    Properties

    standardError?: string

    Content sent to standard error during the execution of the script

    standardOutput?: string

    Content sent to standard output during the execution of the script

    Methods

    • Executes the shell script.

      Parameters

      • arguments: string[]

        An array of string arguments to pass to the script. These will appear to the script as command line arguments would.

      Returns boolean

      true if the script was executed without error, false if not.

    • Convenience method to create a ShellScript object.

      Parameters

      • script: string

        A string containing the shell script. This should contain the appropriate "she bang" to trigger the appropriate scripting language/shell.

      Returns ShellScript