DEV Community

Cover image for I built a Mac menu bar app that rewrites text in any app
Atikur Rahaman
Atikur Rahaman

Posted on

I built a Mac menu bar app that rewrites text in any app

I kept doing the same thing ten times a day: copy a Slack message into a chat window, ask for "more professional" or "shorter", copy the answer, paste it back. So I built Quill, a small macOS menu bar app that does the round trip for me.

Select text in any app, press ⌃⌥Space, pick a prompt, and the rewrite replaces your selection. Undo still works, because Quill pastes through the app's own paste.

  • Prompts: Fix Grammar, Professional, Shorter and Friendly to start. You can add, edit, reorder and delete them, or type a one-off instruction.
  • Direct shortcuts: any prompt can have its own global shortcut, which rewrites the selection without opening the popup.
  • No selection: Quill rewrites the whole text field.
  • Model: it uses your own Groq API key with openai/gpt-oss-20b.

It's written in SwiftUI and AppKit, with no third-party dependencies, and needs macOS 14 or later.

How it works

The hard part isn't the AI call. It's reading and writing text in someone else's app, safely.

1. A global shortcut

Quill registers system-wide hotkeys with Carbon, which still works, and needs no extra permission for this. One shortcut opens the popup. Each prompt can have its own. When two shortcuts clash, Settings flags it instead of silently dropping one.

2. Reading the focused field with Accessibility

When you press the shortcut, Quill asks macOS Accessibility for the focused text element. It reads the element's value and selected range before the popup takes keyboard focus. If nothing is selected, it uses the whole field.

A few details that took real debugging:

  • Ranges are UTF-16. The Accessibility API counts in UTF-16 code units, the same as NSString. Swift's String counts characters, so one emoji is 1 character but 2 UTF-16 units. Mix the two up and the replacement lands in the wrong place.
  • Secure fields are skipped. Password inputs are never read.
  • Chromium needs a nudge. Chrome and Electron apps only build their accessibility tree when asked, so Quill requests it when you invoke it.

Quill doesn't watch your typing or poll other apps. It reads one field, once, when you press the shortcut.

3. The Groq request

The request is a plain URLSession POST to Groq's OpenAI-compatible endpoint:

struct Request: Encodable {
    let model = "openai/gpt-oss-20b"
    let messages: [Message]
    let temperature = 0.3
    let max_completion_tokens = 8192
    let reasoning_effort = "low"
    let include_reasoning = false
}
Enter fullscreen mode Exit fullscreen mode

The system prompt tells the model to treat your text as text to edit, never as instructions, and to return only the rewrite: no labels, quotes or code fences. Your text goes in the user message.

The response is checked before anything touches your document:

  • finish_reason must be "stop". A rewrite cut off at the token limit is never inserted.
  • Empty output is rejected, and your original text stays as it was.
  • 401/403 and 429 get human messages ("Groq rejected the API key", "rate limit reached").
  • Passages are capped at 100 KB, and requests time out after 60 seconds. Escape cancels a request in flight.

4. Putting the text back

This is where most of the code is. Before inserting, Quill:

  1. checks the field still holds the text it captured. If you edited it while the request was running, Quill won't overwrite your changes. It shows the rewrite with a Copy Rewrite button instead.
  2. restores focus and the original selection.
  3. copies that selection again and compares it with what it expects.
  4. pastes the result, so the host app records it as a normal edit and ⌘Z works.

Some editors, like custom controls and some rich-text editors, don't expose their text to Accessibility at all. For those, Quill captures the selection with a quick ⌘C, then restores your previous clipboard. If that fails too, Use Clipboard is the manual fallback: copy, rewrite, paste.

Privacy choices

  • Only the text you rewrite and the prompt are sent, to Groq, when you press the shortcut.
  • There's no writing history, no logging of your text and no automatic retries.
  • The API key is stored in ~/Library/Application Support/Quill/config.json, with file mode 0600 in a 0700 directory. It's written atomically, and symlinks are rejected. Quill doesn't use the Keychain.

Testing without a key

./scripts/test.sh runs a standalone async test harness against the real range utility and Groq client, with mocked URLSession responses. It needs no key or network. It covers Unicode ranges, overflowing ranges, whole-field replacement, request parameters, auth errors, rate limits, and incomplete or empty output.

Everything else is a manual checklist: TextEdit, Safari and Chrome textareas, password fields, editing during a request, multiple displays, full-screen apps, and light/dark mode. Accessibility behaviour depends too much on the host app to unit-test.

Things I learned

  • Don't sandbox it. System-wide Accessibility doesn't work in the App Sandbox.
  • Signing identity matters. An ad-hoc signed rebuild can reset the Accessibility approval, because macOS ties it to the app's code signature. Move the app to /Applications before granting permission.
  • Every app is different. Native fields, Chromium textareas and Electron composers each behave a little differently, which is why the clipboard fallback exists.

Try it

Quill is free. The download is built for Apple Silicon, and Intel Macs can build it from source.

If it fails in an app you use, tell me which one in the comments.

Top comments (0)