Skip to content

Instantly share code, notes, and snippets.

@roelven
Last active April 28, 2025 08:30
Show Gist options
  • Save roelven/73eb3b56ab7ba8499f8d7411bd36c9a7 to your computer and use it in GitHub Desktop.
Save roelven/73eb3b56ab7ba8499f8d7411bd36c9a7 to your computer and use it in GitHub Desktop.
Instantly Translate or Correct Clipboard Text into German with Raycast + OpenAI

Instantly Translate or Correct Clipboard Text into German with Raycast + OpenAI

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

πŸ“‹ Prerequisites

  • MacOS with Raycast
  • OpenAI API key (platform.openai.com)
  • jq installed for parsing JSON:

brew install jq

βš™οΈ Setup

  1. Create new file in your Raycast Script Commands folder (e.g., ~/.raycast/scripts/translate_to_german.sh).

  2. Paste the script below into the file.

  3. Make the script executable: chmod +x ~/.raycast/scripts/translate_to_german.sh

  4. Replace YOUR_OPENAI_API_KEY_HERE with your actual OpenAI API key.

  5. Reload Raycast script directories

  6. Set a keyboard shortcut to trigger it even faster (I use βŒ₯ + ⇧ + G)

πŸš€ The Script


#!/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\""

πŸ’‘ Notes

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment