Skip to main content

Command Line

The command line tool is compatible with container and virtual machines so you can run it in Docker, GitHub Codespaces, ...

Setting up the project

Let's get started by installing the DeviceScript command line and create an empty project

  • Open a terminal in a new folder
  • install Node.js 18+ if not already installed
  • Use the init command to setup a new project
npx --yes @devicescript/cli@latest init

You will have the following files created.

.devicescript/     reserved folder for devicescript generated files
package.json project configuration
devsconfig.json configure the DeviceScript compiler with additional flags,
also used by VSCode extension to activate.
src/ directory for DeviceScript sources
src/main.ts usual name for your entry point application
src/tsconfig.json configure the TypeScript compiler to compile DeviceScript syntax
  • open src/main.ts and copy the following code
import * as ds from "@devicescript/core"
import { debounceTime, filter } from "@devicescript/observables"

const sensor = new ds.AirPressure()
const mouse = new ds.HidMouse()
// listen for pressure changes
filter(pressure => pressure > 1400),
.subscribe(async () => {
await mouse.setButton(

Launch the build watch

Assuming src/main.ts is the root file of your application, launch a compilation task in watch mode using this command.

devs devtools src/main.ts

or, for short,

yarn watch

The command line task will also start a local web server that will send the compiled bytecode to a developer tools page similar to the one hosted in the docs.

  • open the developer tools page, typically http://localhost:8081/ (see cli output)
  • use te developer tools page similarly to the embedded docs page

Edit, deploy, debug loop

From here, your developer inner loop will be very similar to building/debugging a web site with hot reload.

  • make an edit in your source file, say src/main.ts
  • after a couple seconds, the compiler picks up the changes, produces a new bytecode and sends it to the developer tools
  • the developer tools automatically deploy the bytecode to the select device (by default the simulator)
  • switch from VS Code to the browser and debug your new code