hammerspoon2-docs
    Preparing search index...

    Class HSTask

    Object representing an external process task

    Index
    environment: Record<string, string>

    The environment variables for the task

    Can only be modified before calling start()

    isRunning: boolean

    Check if the task is currently running

    true if the task is running, false otherwise

    pid: number

    The process ID of the running task

    The value will be -1 if the task is not running

    terminationReason: string | null

    The termination reason

    Returns a string describing why the task terminated, or nil if still running: "exit" if the task exited, "uncaughtSignal" if a signal killed it, or "launchFailed" if its program could not be started

    terminationStatus: number | null

    The termination status of the task

    Returns the exit code, or nil if the task hasn't terminated

    workingDirectory: string | null

    The working directory for the task

    Can only be modified before calling start()

    • Wait for the task to exit, blocking Hammerspoon until it does

      Parameters

      • Optionaltimeout: number

        The most time to wait, in seconds. Leave it out (or pass null or Infinity) to wait for as long as the task runs. 0 or a negative number doesn't wait.

      Returns boolean

      true if the task isn't running, false if it was still running when the time ran out

      Nothing else in your configuration runs while this waits: timers, hotkeys and other callbacks are delayed until it returns. Use waitUntilExit() to wait without blocking. A task that never finishes blocks Hammerspoon forever unless you give a timeout, so always give one where that would be a problem, e.g. in hs.onShutdown.

    • Close the task's stdin

      Returns void

      Any data passed to sendInput() is still written before stdin is closed.

    • Interrupt the task (send SIGINT)

      Returns void

    • Terminate the task with extreme prejudice (send SIGKILL)

      Returns void

    • Pause the task (send SIGSTOP)

      Returns void

    • Resume the task (send SIGCONT)

      Returns void

    • Write data to the task's stdin

      Parameters

      • data: string

        The string data to write

      Returns void

      The data is written in the background, in the order sendInput() was called, so a large write doesn't block Hammerspoon while the task reads it. It has no effect before the task has started, after it has finished, or after closeInput().

    • Start the task

      Returns HSTask

      The task object for chaining

      A running task, and its callbacks, stay alive until it terminates, even if you don't keep a reference to it. Use terminate() to stop it early.

    • Terminate the task (send SIGTERM)

      Returns void

    • Wait for the task to exit, without blocking Hammerspoon

      Parameters

      • Optionaltimeout: number

        The most time to wait, in seconds. Leave it out (or pass null or Infinity) to wait for as long as the task runs. 0 or a negative number doesn't wait.

      Returns Promise<boolean>

      A Promise that resolves to true once the task isn't running (after its termination callback has been called, so all its output has been delivered), or to false if it was still running when the time ran out