// Name: Select SuperWhisper Mode // Description: Opens SuperWhisper with a selected mode. // Author: tayiorbeii import "@johnlindquist/kit"; import { Choice } from "@johnlindquist/kit"; import { readFile } from 'node:fs/promises'; const modesDir = home('Documents', 'superwhisper', 'modes'); try { const files = await readdir(modesDir); const choices: Choice[] = []; for (const file of files) { if (file.endsWith('.json')) { const filePath = path.join(modesDir, file); try { const content = await readFile(filePath, 'utf8'); const mode = JSON.parse(content); choices.push({ name: mode.name, value: mode.key, description: file, }); } catch (parseError) { console.error(`Error parsing JSON file ${file}:`, parseError); continue; // Skip to the next file } } } const selectedMode = await arg('Select a mode', choices); await open(`superwhisper://mode?key=${selectedMode}`); } catch (readDirError) { console.error(`Error reading modes directory:`, readDirError); exit(1); // Exit the script with an error code }