import '@johnlindquist/kit'
const captureAreas = ["full", "window", "selection"] as const;
type CaptureArea = typeof captureAreas[number];
const area = await arg<CaptureArea>("Select area", captureAreas);
const filename = await arg("Enter filename", `${Date.now()}.png`);
const savePath = kenvPath("screenshots", filename);
await ensureDir(kenvPath("screenshots"));
let captureCommand = "";
switch (area) {
case "selection":
captureCommand = `screencapture -i ${savePath}`;
break;
case "window":
captureCommand = `screencapture -w ${savePath}`;
break;
case "full":
captureCommand = `screencapture -x ${savePath}`;
break;
default:
throw new Error(`Invalid capture area: ${area}`);
}
try {
await exec(captureCommand);
} catch (error:any) {
console.error(`Failed to capture screenshot: ${error.message}`);
process.exit(1);
}
const share = await arg("Share Screenshot?", ["yes", "no"]);
if (share === "yes") {
await copy(savePath);
await notify(`Copied path of ${filename}`);
}
await revealFile(savePath);