Watch for File Changes

Watch a Single File

The // Watch metadata enables you to watch for changes to a file on your system.

// Name: Speak File
// Watch: ~/speak.txt
import "@johnlindquist/kit"
let speakPath = home("speak.txt")
try {
let content = await readFile(speakPath, "utf-8")
if (content.length < 60) {
// We don't want `say` to run too long 😅
} catch (error) {

Open speak-file in Script Kit

Watch a Directory

The // Watch metadata uses Chokidar under the hood, so it supports the same glob patterns.

// Name: Download Log
// Watch: ~/Downloads/*
import "@johnlindquist/kit"
// These are optional and automatically set by the watcher
let filePath = await arg()
let event = await arg()
if (event === "add") {
await appendFile(home("download.log"), filePath + "\n")

Open download-log in Script Kit

Discuss Post