Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⌨️ hotkey-translate (macOS)

Put your cursor in any French text field, press Ctrl+T, and the whole field is instantly replaced by the English translation — in place, in any app, with no visible selection.

Works everywhere: your browser (any web field), Mail, Slack, Notion, a note… The translation runs on a local LLM on your Mac (private, offline, free) via Ollama, with a free online fallback if Ollama isn't set up.

Why

If you write in French but often need to send in English, round-tripping through a translation site is tedious. This makes it a single keystroke, right where you type — no window switching, no copy-paste dance.

How it works

Cursor in a French field  →  press Ctrl+T
        │
        ▼
Read the whole field value (Accessibility API; clipboard fallback)
        │
        ▼
Translate locally with Ollama (qwen2.5:3b)   — private, ~1s
        │
        ▼
Write English back via the Accessibility API (no selection, no flash;
paste fallback for apps that don't expose their field value)

Three small pieces:

Piece Role
Ollama + a small model (qwen2.5:3b) local, private translation engine
bin/translate.sh FR→EN via Ollama's HTTP API; MyMemory fallback
Hammerspoon config the global Ctrl+T hotkey + read/replace logic

Requirements

  • macOS (Apple Silicon recommended)
  • Homebrew
  • The installer pulls the rest: Hammerspoon, Ollama, and the model.

Install

git clone https://github.com/benjaminb10/hotkey-translate.git
cd hotkey-translate
./install.sh

Then:

  1. Add this line to ~/.hammerspoon/init.lua:
    dofile(os.getenv("HOME") .. "/hotkey-translate/hammerspoon/translate.lua")
    (adjust the path to wherever you cloned it)
  2. Launch Hammerspoon and grant it Accessibility (System Settings → Privacy & Security → Accessibility → add Hammerspoon) — this is required to read the selection and paste the result. Then click the Hammerspoon menu-bar icon → Reload Config.

Usage

Put your cursor in any French text field, press Ctrl+T. A brief 🌐 Translating… appears, then the whole field is replaced by the English — no manual selection, no visible highlight.

Configuration

  • Hotkey — edit HOTKEY_MODS / HOTKEY_KEY at the top of hammerspoon/translate.lua.
  • Model / quality vs. speed — set OLLAMA_MODEL (e.g. qwen2.5:7b for higher quality, a 3B for speed). bin/translate.sh reads it.
  • Languages — the prompt in bin/translate.sh targets French → English; change it there for other pairs.

Privacy

With Ollama, the text never leaves your Mac — no key, no account, offline. The online MyMemory fallback is only used if Ollama isn't reachable; disable it by removing the fallback block in bin/translate.sh if you want strictly local.

Notes & limitations

  • Ctrl+T overrides the rarely-used Cocoa "transpose characters" binding.
  • Some apps expose selected text poorly; the clipboard fallback covers most.
  • Quality is whatever the chosen local model gives (qwen2.5:3b handles idioms like « sans faute » → "without fail" well).

Credits

  • Hammerspoon — the macOS automation glue
  • Ollama + Qwen2.5 — the local translation engine
  • MyMemory — free online fallback

License

MIT

About

Press Ctrl+T to translate your selected text to English, in place, in any macOS app. Local & private via Ollama, free online fallback. Hammerspoon.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages