// Name: Watch Screen Captures for MP4 // Description: Watches ~/Documents/Screen Captures for new .mp4 files and runs 'transcribe-locally-with-parakeet' on each new file. // Author: tayiorbeii // GitHub: tayiorbeii import "@johnlindquist/kit" import chokidar from "chokidar" const watchDir = home("Documents", "Screen Captures") await ensureDir(watchDir) const pattern = path.join(watchDir, "*.mp4") const processed = new Set<string>() const watcher = chokidar.watch(pattern, { ignoreInitial: true, awaitWriteFinish: { stabilityThreshold: 2000, pollInterval: 250 }, }) watcher.on("add", async addedPath => { try { if (processed.has(addedPath)) return processed.add(addedPath) // small delay to ensure filesystem settled await wait(500) const latest = await getLatestMp4(watchDir) if (!latest) return await run("transcribe-locally-with-parakeet", latest) } catch (err) { console.error(err) } }) await hide() async function getLatestMp4(dir: string): Promise<string | null> { const entries = await readdir(dir) const mp4s = entries.filter(n => n.toLowerCase().endsWith(".mp4")) if (!mp4s.length) return null let latestPath = "" let latestTime = -1 for (const name of mp4s) { const full = path.join(dir, name) const stats = await stat(full) const mtime = stats.mtimeMs if (mtime > latestTime) { latestTime = mtime latestPath = full } } return latestPath || null }