hs.task
ModuleModule for running external processes
Types
This module provides the following types:
Properties
hs.task.sequence
function | null
Run multiple tasks in sequence. Swift-retained storage for the JS implementation.
hs.task.TaskBuilder
function | null
TaskBuilder class. Swift-retained storage for the JS implementation.
Methods
hs.task.create(launchPath, arguments, completionCallback, environment, streamingCallback) -> HSTask
Create a new task
Declaration
hs.task.create(launchPath, arguments, completionCallback, environment, streamingCallback) -> HSTask
Parameters
| Name | Type | Description |
|---|---|---|
| launchPath | string | The full path to the executable to run |
| arguments | string[] | An array of arguments to pass to the executable |
| completionCallback | function | null | Optional callback called when the task terminates with exit code and reason |
| environment | [String: String] | Optional dictionary of environment variables for the task |
| streamingCallback | function | null | Optional callback called when the task produces output; stream is "stdout" or "stderr" |
Returns
HSTask
A task object. Call start() to begin execution.
Example
const task = hs.task.create("/usr/bin/env", ["printenv", "PATH"], (code, reason) => {
console.log("exited", code)
})
task.start()
hs.task.runAsync(launchPath, args, options, legacyStreamCallback) -> any
Create and run a task asynchronously
Declaration
hs.task.runAsync(launchPath, args, options, legacyStreamCallback) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| launchPath | string | - Full path to the executable |
| args | string[] | - Array of arguments |
| options | Object|Function | - Options object or legacy callback |
| legacyStreamCallback | Function | - Legacy streaming callback (optional) |
Returns
any
{Promise<{exitCode: number, stdout: string, stderr: string}>}
hs.task.shell(command, options) -> any
Run a shell command asynchronously
Declaration
hs.task.shell(command, options) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| command | string | - Shell command to execute |
| options | Object | - Options (same as run) |
Returns
any
{Promise<{exitCode: number, stdout: string, stderr: string}>}
hs.task.parallel() -> any
Run multiple tasks in parallel
Declaration
hs.task.parallel() -> any
Returns
any
{Promise<Array<{exitCode: number, stdout: string, stderr: string}>>} Array of results
hs.task.builder(launchPath) -> any
Create a task builder for fluent API
Declaration
hs.task.builder(launchPath) -> any
Parameters
| Name | Type | Description |
|---|---|---|
| launchPath | string | - Full path to the executable |
Returns
any
{TaskBuilder}