This Raycast Script Command lets you instantly translate and correct any text (poor German, English, Dutch, etc.) into grammatically correct German β triggered by a shortcut on macOS.
The script:
- Reads the current clipboard text
- Sends it to OpenAI's GPT-4 Turbo model
- Receives corrected German
- Copies the result back to your clipboard
- Displays a small macOS notification when done
- MacOS with Raycast
- OpenAI API key (platform.openai.com)
- jq installed for parsing JSON:
brew install jq
-
Create new file in your Raycast Script Commands folder (e.g.,
~/.raycast/scripts/translate_to_german.sh
). -
Paste the script below into the file.
-
Make the script executable:
chmod +x ~/.raycast/scripts/translate_to_german.sh
-
Replace
YOUR_OPENAI_API_KEY_HERE
with your actual OpenAI API key. -
Reload Raycast script directories
-
Set a keyboard shortcut to trigger it even faster (I use
β₯ + β§ + G
)
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Translate to German
# @raycast.mode silent
# Optional parameters:
# @raycast.icon π
# @raycast.packageName Language Tools
# Documentation:
# @raycast.description Translates clipboard text into grammatically correct German using GPT-4 and copies it back to clipboard.
# @raycast.author Roel van der Ven
# @raycast.authorURL https://roelvanderven.com
# CONFIGURATION
OPENAI_API_KEY="YOUR_OPENAI_API_KEY_HERE"
# Read clipboard
INPUT=$(pbpaste)
# API request
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"gpt-4-turbo\",
\"messages\": [
{\"role\": \"system\", \"content\": \"Translate the text into grammatically correct German. Only output the corrected German text. No comments.\"},
{\"role\": \"user\", \"content\": \"$INPUT\"}
],
\"temperature\": 0.2
}")
# Parse output
TRANSLATED=$(echo $RESPONSE | /usr/bin/jq -r '.choices[0].message.content')
# Copy to clipboard
echo "$TRANSLATED" | pbcopy
# Notify user
osascript -e "display notification \"Corrected German copied to clipboard!\" with title \"Translation Done\""
If you want the output displayed inside Raycast instead of just copying to clipboard, you can modify the script to output the translated text directly instead of staying "silent." You can easily adapt this script to use your local LLMs (e.g., LibreChat or Ollama) if you rather want this to work without using the cloud.