Skip to content

Instantly share code, notes, and snippets.

@tayiorbeii
Created February 12, 2025 20:58
Show Gist options
  • Save tayiorbeii/72395075ef266c6b5815c5f924c79e3c to your computer and use it in GitHub Desktop.
Save tayiorbeii/72395075ef266c6b5815c5f924c79e3c to your computer and use it in GitHub Desktop.
// Name: Superwhisper Mode Selector
// Author: Taylor Bell
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,
});
} catch (parseError) {
console.error(`Error parsing JSON file ${file}:`, parseError);
continue;
}
}
}
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment