🚀 Build a One-Key AI Rephrasing Tool on Windows Using Gemini, PowerShell & AutoHotkey

Build a One-Key AI Rephrasing Tool on Windows (Gemini + PowerShell + AutoHotkey)
Practical AI • Windows Automation • Clipboard Tool

Build a One-Key AI Rephrasing Tool on Windows
using Gemini, PowerShell & AutoHotkey

Copy any text, press a hotkey, paste a polished version in professional English — no browser, no UI, no context switching.

Hotkey: Ctrl + Alt + R Input: Clipboard Output: Clipboard Model: gemini-flash-latest

What this tool does

As developers and consultants, we constantly rephrase text — emails, documentation, PR comments, proposals, and updates. Switching tabs to an AI chat tool breaks flow.

Goal: Make AI rephrasing feel native to Windows: CopyHotkeyPaste.

1) Copy

Select any text and copy it to clipboard.

2) Hotkey

Press Ctrl+Alt+R to trigger Gemini.

3) Paste

The rephrased result is already in clipboard.

Architecture overview

This solution uses two lightweight pieces:

PowerShell script (the brain)

  • Reads input from clipboard (or a file)
  • Calls Gemini generateContent API
  • Uses a strict “rephrase only” prompt
  • Copies the result back to clipboard

AutoHotkey script (the trigger)

  • Listens for a global hotkey
  • Runs the PowerShell script silently
  • Shows a small completion notification

PowerShell: GeminiRephrase.ps1

This script reads your clipboard text, sends it to Gemini, and puts the rephrased output back into the clipboard. Keep the API key in an environment variable named GEMINI_API_KEY.

param(
  [Parameter(ValueFromRemainingArguments = $true)]
  [string[]] $Path
)

# API key from environment variable
$apiKey = $env:GEMINI_API_KEY
if ([string]::IsNullOrWhiteSpace($apiKey)) {
  Write-Host "GEMINI_API_KEY is not set. Set it and retry." -ForegroundColor Red
  exit 1
}

# Model + endpoint
$model = "gemini-flash-latest"
$endpoint = "https://generativelanguage.googleapis.com/v1beta/models/$model`:generateContent?key=$apiKey"

# Input: file (optional) or clipboard
$text = $null
if ($Path -and $Path.Count -gt 0 -and (Test-Path $Path[0])) {
  $text = Get-Content -Raw -LiteralPath $Path[0]
} else {
  $text = Get-Clipboard -Raw
}

if ([string]::IsNullOrWhiteSpace($text)) {
  Write-Host "No input text found (file/clipboard is empty)." -ForegroundColor Yellow
  exit 0
}

# Prompt: rephrase only
$prompt = @"
Just Repharase it.
Dont ask any questions.

TEXT:
$text
"@

# Request body
$bodyObj = @{
  contents = @(
    @{
      parts = @(
        @{ text = $prompt }
      )
    }
  )
}
$bodyJson = $bodyObj | ConvertTo-Json -Depth 10

try {
  $resp = Invoke-RestMethod -Method Post -Uri $endpoint -ContentType "application/json" -Body $bodyJson
  $out = $resp.candidates[0].content.parts[0].text

  if ([string]::IsNullOrWhiteSpace($out)) {
    Write-Host "No output returned." -ForegroundColor Yellow
    exit 0
  }

  Set-Clipboard -Value $out
  Write-Host "`n--- Rephrased (copied to clipboard) ---`n"
  Write-Output $out
} catch {
  Write-Host "Request failed:" -ForegroundColor Red
  Write-Host $_.Exception.Message -ForegroundColor Red
  if ($_.ErrorDetails -and $_.ErrorDetails.Message) {
    Write-Host $_.ErrorDetails.Message -ForegroundColor DarkRed
  }
  exit 1
}
Tip: If you want “professional English” specifically, update the prompt to something like: Rewrite in professional, clear English. Keep meaning. Fix grammar. No new info.

AutoHotkey: global hotkey

AutoHotkey makes the tool feel native: press a hotkey, run the PowerShell script hidden, and notify when done. This is for AutoHotkey v2.

#Requires AutoHotkey v2.0
#SingleInstance Force

; Hotkey: Ctrl + Alt + R
^!r::{
    psScript := "C:\Users\ghous.sarwar_codup\Downloads\Own\GeminiRephrase.ps1"
    cmd := 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "' psScript '"'
    RunWait cmd, , "Hide"

    ; AHK v2 signature: TrayTip(Text, Title?)
    TrayTip "Done — result copied to clipboard ✅", "Gemini Rephrase"
}

Run on startup (optional)

Put your .ahk file in the Startup folder: Win + Rshell:startup

Prerequisite: Install AutoHotkey

This tool requires AutoHotkey v2 to register a global keyboard shortcut on Windows. AutoHotkey is a lightweight and widely used automation tool for Windows.

  • Download AutoHotkey from the official website: https://www.autohotkey.com/
  • Select AutoHotkey v2 during installation (v1 is not compatible).
  • Allow the installer to associate .ahk files with AutoHotkey.
After installation, double-clicking a .ahk file should start it immediately and show a green AutoHotkey icon in the system tray.

Security notes

  • Keep your API key out of scripts; use GEMINI_API_KEY environment variable.
  • If you accidentally shared your key (screenshots, commits), rotate it immediately.
  • Consider usage limits / restrictions in your Google project to prevent abuse.

© • Built for fast, practical writing improvement on Windows.

Comments