Nova Tasks

Nova’s Tasks system allow you to easily run scripts from within Nova for building, running, or cleaning your project. They support a number of scripting languages, and can be run either locally or on a remote server over SSH. You can write your own custom Tasks within Nova, and some Extensions may provide their own preconfigured Task templates as well.

We’ll focus on creating Custom Tasks for the rest of this article, but many of the concepts will apply to extension-provided tasks too.


Creating a Task

Creating a new Task in Project Settings.

Tasks can be managed from the Project menu > Project Settings. You can select an existing Task from the sidebar on the left, or click the + icon to create a new Task. Having multiple Tasks allows you to have different configurations for different scenarios. For your instance, you may have a “Debug” Task for building debug versions of your project, and a “Release” Task for release builds.

Note: Tasks are only available in local projects, and cannot be created in remote-only projects or outside of a project.

Once you create your Task, you’ll be able to write and configure it to suit your needs.

Actions

Tasks can define behavior for up to three different actions:

  • Build
  • Run
  • Clean

Each action type can be defined however you need. For example, you could:

  • Start a local web server
  • Kick off a build script
  • Run a processor or preprocessor
  • Clean up build artifacts

Depending on your project requirements, you might define only one action for your task, but any combination of Build, Run, and Clean may be defined as needed.

Writing Your Task Script

The user interface for configuring Tasks.

Once you’ve decided whether to write a Build, Run, or Clean script, check “Enable the (Build/Run/Clean) action for this Task”. Next, you can use the Where field to tell Nova to either run this script on your local Mac, or select a remote server to execute your script over SSH.

You can write your script directly in the Script field, or you can select the Path option to point Nova to an existing script file. Tasks support a number of scripting languages:

  • Shell scripts
  • JavaScript
  • Lua
  • Perl
  • PHP
  • Python
  • Ruby
  • TypeScript

Some scripting languages may require you to install an interpreter separately in order to execute them. You can point Nova to the interpreter’s executable from the Interpreter field.

Note: Task scripts in Nova run in a non-interactive shell. Tools that require user input may not work correctly.

Open Report allows you to choose how to view the output of your script. You can have the report open as soon as you run the Task, after the task has finished running, only if the task is successful or fails, or simply never open the report. You can also choose to show a progress indicator in Nova’s toolbar while a Task script is actively running.

Arguments

A powerful advanced feature of Tasks is the ability to pass Arguments. You can configure these from the Arguments tab:

The Arguments tab.

Here, you can specify arguments to pass to your Task scripts, as well as set environment variables for the script’s shell environment. You can also use wildcards to dynamically pass information about your project or files - such as your current file’s name or your current Git branch - to your script. For instance, you can pass the relative file path of the currently opened file to your script using the Relative File Path wildcard…

Passing a wildcard as an argument.

… and then access the argument using $ syntax in a shell script.

Calling the argument from a shell script.

Task Pipelines

Some build processes can be a bit more complicated than running a single script. For that, Nova has Task pipelines. In addition to the main script set for a Build, Run, or Clean action, you can also configure a multi-step pipeline of other actions to take when running a Task.

To configure a Task Pipeline, expand the Task in the sidebar and select the action whose pipeline you want to configure.

Editing the pipeline for the Build step of a custom Task.

By default, the only step in an action’s pipeline is the action itself. You can add additional steps by clicking the + icon in the pipeline’s timeline. Actions you can add include:

  • Running an additional script
  • Running another Task
  • Playing a sound
  • Speaking text

You can drag and reorder the steps however you want. For instance, you can add a step of running a script before Nova runs your Build script, then have Nova run a clean-up task after building, and finally play a sound when everything is complete.

An example of a multi-step pipeline.

Invoking Actions

Once you have a task configured, Nova provides several different methods for invoking the actions it defines:

Toolbar

Task options in Nova's toolbar.

Build and Run actions are available in the Tasks section of the toolbar. A Stop action is also available while a Task script is executing. If you have multiple Task configurations in a given project, a dropdown menu is available in the toolbar to select which Task configuration to use.

Build, Run, and Clean are all available under the Project menu and can also be invoked using their keyboard shortcuts.

  • Command-B to Build
  • Command-R to Run
  • Command-Shift-K to Clean
  • Command-. to Stop (only while a Task is running)

Command Palette

Build, Run, and Clean are all available from the Command Palette:

Tasks showing in command palette.

Let’s take a closer look at how you might configure a new Custom Task to work with an existing project.

Next…
Part 2: Taskifying NPM Scripts

This article was last updated on March 26, 2024