import type { SourceModule } from "../registry"; import { runOsa, parseRows, osaQuote } from "@/lib/mac"; import { ThingsConfig, ThingsPayload, type ThingsConfig as Config, type ThingsPayload as Payload, } from "@/lib/schemas/sources/things"; // Pulls a Things 3 list (default "Today") via AppleScript. Read here; completion // happens through /api/integrations/things/complete. Registered under kind "todos". export const thingsModule: SourceModule = { kind: "todos", label: "Today", keyless: true, // local app, no API key defaultRefreshSeconds: 300, configSchema: ThingsConfig, payloadSchema: ThingsPayload, async fetch({ config }) { const script = [ `set fs to (ASCII character 31)`, `set rs to (ASCII character 30)`, `set output to ""`, `tell application "Things3"`, ` repeat with t in to dos of list ${osaQuote(config.list)}`, ` set pj to ""`, ` try`, ` set pj to name of project of t`, ` end try`, ` set output to output & (id of t) & fs & (name of t) & fs & pj & rs`, ` end repeat`, `end tell`, `return output`, ].join("\n"); const rows = parseRows(await runOsa(script)); return { list: config.list, tasks: rows.map(([id, title, project]) => ({ id: id ?? "", title: title ?? "", project: project ?? "", })), }; }, };