In this post, we’ll create a highly useful Mac tool to fix the grammar of any selected text.
The heart of this tool is the fixGrammar function, a straightforward utility that takes a piece of text as input and returns a grammatically corrected version.
To use this function, you’ll need to set up your OpenAI API key in your environment variables.
We use a mini model to keep the responses fast and cost-effective. The max_tokens parameter defines the maximum number of tokens generated in the response, while the temperature parameter controls the response's randomness.
This AppleScript automates grammar correction for selected text.
The readStdin function is responsible for capturing input text from the standard input and returning a promise that resolves with the trimmed text.
To execute scripts with node, we need to bundle them into a single file using esbuild.
For AppleScript to execute the JavaScript file, it needs to know the path to the node executable and the script file.
To run the workflow using a shortcut, assign it a custom shortcut in System Preferences.
With this setup, you now have a powerful Mac tool to fix grammar in any selected text effortlessly.