AppleScript that uses the Gemini language model API (by Google) to enhance the writing, spelling, and formality of selected text. The automation works directly on macOS, allowing you to select any text from applications and run the automation to improve it.
- Open Automator on macOS.
- Choose the "Workflow" option.
- In the field "The workflow receives current:", select "text", and in the field "in:", select "any application".
- In the sidebar, under Library, search for and drag the "Run AppleScript" block into the workflow.
- Copy the code from the
service.applescript
file in this repository and paste it into the AppleScript block in Automator. - Modify the code as needed:
- Prompt: Change the
prompt
variable to adjust how the AI should respond (e.g., if you want to change the level of formality or add specific instructions). - API Key: Replace
"<YOUR-GEMINI-API-KEY-HERE>"
with your own Gemini API key.
- Prompt: Change the
The script uses the following tools to make the request and process the returned JSON:
- curl: Command-line tool for transferring data.
- Version used:
curl 8.7.1 (x86_64-apple-darwin23.0)
- Version used:
- jq: Command-line tool for processing JSON.
- Version used:
jq-1.7.1
- Version used:
You can install both curl
and jq
via Homebrew:
brew install curl jq
The script requires the exact path to the jq
binary. To find the correct path, run the following command in the terminal:
which jq
Replace the jq
path in the script, if necessary, with the one returned by the command. If installed via Homebrew, the path will typically be:
/opt/homebrew/bin/jq
- After configuring the script, save the automation with the name "Improve Text With Gemini".
- To use it, select text in any application, go to the "Services" menu, and click on "Improve Text With Gemini".
- The automation will run, and a popup with the enhanced text will appear.
You can customize the script's behavior by modifying the prompt
variable to adjust how the Gemini language model processes the text:
set prompt to "......."
And don’t forget to replace <YOUR-GEMINI-API-KEY-HERE>
with your API key.
This project is open-source. Feel free to modify, improve, and share it.