Create new instance.
Content sent to standard error during the execution of the script
Content sent to standard output during the execution of the script
Executes the shell script.
An array of string arguments to pass to the script. These will appear to the script as command line arguments would.
true
if the script was executed without error, false
if not.
Convenience method to create a ShellScript object.
A string containing the shell script. This should contain the appropriate "she bang" to trigger the appropriate scripting language/shell.
Generated using TypeDoc
ShellScript
macOS only. Requires Drafts 19 or greater.
ShellScript objects can be used to execute Unix shell scripts.
Bash Example
// 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); }
Ruby Example
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.