// Name: AI-Powered Text Processor // Description: Process and transform text using AI with various operations // Author: Script Kit User import "@johnlindquist/kit" // Get text from user - either selected text or manual input let inputText = await getSelectedText() if (!inputText?.trim()) { inputText = await editor({ placeholder: "Enter text to process...", hint: "Type or paste text that you want to transform using AI" }) } if (!inputText?.trim()) { await div(md("No text provided. Exiting...")) exit() } // Define available AI operations const operations = [ { name: "Summarize", value: "summarize", description: "Create a concise summary of the text", prompt: "Summarize the following text in a clear and concise manner:" }, { name: "Improve Writing", value: "improve", description: "Enhance clarity, grammar, and style", prompt: "Improve the writing quality, grammar, and clarity of the following text while maintaining its original meaning:" }, { name: "Make Professional", value: "professional", description: "Convert to professional tone", prompt: "Rewrite the following text in a professional, business-appropriate tone:" }, { name: "Make Casual", value: "casual", description: "Convert to casual, friendly tone", prompt: "Rewrite the following text in a casual, friendly tone:" }, { name: "Translate", value: "translate", description: "Translate to another language", prompt: "Translate the following text to" }, { name: "Extract Key Points", value: "keypoints", description: "Extract main points as bullet list", prompt: "Extract the key points from the following text and present them as a clear bullet list:" }, { name: "Expand", value: "expand", description: "Add more detail and context", prompt: "Expand on the following text by adding more detail, context, and explanation:" }, { name: "Simplify", value: "simplify", description: "Make easier to understand", prompt: "Simplify the following text to make it easier to understand, using simpler words and shorter sentences:" } ] // Let user choose operation const selectedOperation = await arg("Choose AI operation:", operations) let finalPrompt = selectedOperation // Handle translation specially to get target language if (selectedOperation === "translate") { const targetLanguage = await arg("Translate to which language?", [ "Spanish", "French", "German", "Italian", "Portuguese", "Chinese", "Japanese", "Korean", "Russian", "Arabic" ]) finalPrompt = `${selectedOperation} ${targetLanguage}:` } // Create AI processor const processor = ai(finalPrompt) // Show processing indicator let result = "" await div({ html: md(` # Processing Text... **Operation:** ${selectedOperation} **Original Text:** > ${inputText.substring(0, 200)}${inputText.length > 200 ? "..." : ""} **Processing with AI...** `), onInit: async () => { try { result = await processor(inputText) submit(result) } catch (error) { submit(`Error processing text: ${error.message}`) } } }) // Show result and options const action = await div({ html: md(` # AI Processing Complete **Operation:** ${selectedOperation} **Original Text:** > ${inputText} **Processed Result:** > ${result} `), shortcuts: [ { name: "Copy Result", key: "cmd+c", onPress: async () => { await copy(result) await toast("Result copied to clipboard!") submit("copied") }, bar: "right" }, { name: "Replace Selected", key: "cmd+r", onPress: async () => { await setSelectedText(result) await toast("Text replaced!") submit("replaced") }, bar: "right" }, { name: "Edit Result", key: "cmd+e", onPress: async () => { submit("edit") }, bar: "right" } ] }) // Handle edit action if (action === "edit") { const editedResult = await editor({ value: result, hint: "Edit the AI-processed text as needed" }) await setSelectedText(editedResult) await toast("Edited text applied!") }