← All guides

Writing the watcher script

The entire contract, in one sentence: your script runs, prints one line of data, and exits. TrackFlow takes care of everything else.

The contract

  • TrackFlow re-launches your script on the interval you chose (every 30 seconds, minute, 5 minutes, or 15 minutes).
  • Your script should print one line of JSON describing whatever you want tracked, then exit normally.
  • If your script prints other lines too (progress messages, debug output, warnings) that's fine — TrackFlow only pays attention to the last non-empty line it printed.
  • The JSON can contain whatever fields you want, with whatever names you want. TrackFlow doesn't need to know your field names in advance.

A minimal example

This is a complete, working watcher body in PowerShell — the language TrackFlow starts you off with:

$dati = @{
    valore = 42
    etichetta = "esempio"
}
$dati | ConvertTo-Json -Compress

The same idea in Python:

import json

print(json.dumps({"valore": 42, "etichetta": "esempio"}))

Both print exactly one line: {"valore":42,"etichetta":"esempio"}. That's all TrackFlow needs.

Supported languages

TrackFlow looks at the file extension of the script you point it at and picks the matching interpreter automatically:

ExtensionRuns with
.ps1PowerShell (the default — every new watcher starts with a watcher.ps1)
.py / .pywPython
.jsNode.js
.cmd / .batWindows batch, via cmd /C
Anything elseRun directly as a program — useful for pointing at an already-compiled .exe

The runtime for whatever language you pick (Python, Node, …) has to already be installed on your computer and available on your PATH — TrackFlow doesn't install one for you. If it's missing, that shows up clearly in the watcher's own log — see Managing one afterwards — instead of anywhere silent.

Where the script lives

Each watcher gets its own folder on disk, and its script can be opened, edited, and saved with any editor you like while TrackFlow keeps running it in the background — there's no need to restart the app after editing the file's contents. The folder also contains a small file called watcher.json, which TrackFlow keeps hidden — that's its own internal settings for this watcher (interval, which script to run, and so on), and it's managed entirely from inside the app, never by hand.

Next: Creating one in the app.