{
  "id": 12942274,
  "title": "What I learned building a system-wide AI writing tool on macOS",
  "url": "https://urgent.news/2026/10/08/what-i-learned-building-a-system-wide-ai-writing-tool-on-macos",
  "topic": "ai",
  "section": "AI",
  "published": "2026-10-08T20:06:42.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/godnick/what-i-learned-building-a-system-wide-ai-writing-tool-on-macos-81m"
  },
  "original_language": "en",
  "account": "DraftKey is an on-device writing assistant designed to work with various text fields across different applications on macOS. The main challenge of building such a system-wide AI writing tool on macOS is to find and read the text from the focused text field, as there is no public API that directly provides this information. Instead, the Accessibility API, which is also used by screen readers like VoiceOver, is employed to achieve this.\n\nThe process involves asking for Accessibility permission from the user, creating a system-wide element, and querying it for certain attributes like kAXFocusedUIElementAttribute to identify the focused text field. Reading attributes such as kAXValueAttribute, kAXSelectedTextAttribute, and kAXSelectedTextRangeAttribute allows obtaining the text and cursor position. Additional parameterized attributes can be used to draw UI near the caret.\n\nHowever, not all editors expose their text, making support dependent on how each app exposes its text. For instance, editors that draw their own text, like many code editors, terminals, and canvas-based web apps, may provide a focused element with no usable value or selection. Chromium and Electron apps often build a fuller accessibility tree only after assistive tech is detected, leading to inconsistencies in the accessibility data presented.\n\nDraftKey aims to work in compatible text fields, offer per-app controls to choose where it runs, and avoid secure fields entirely. Writing back to text involves setting the selected text through Accessibility, although this method may not always work, and the common fallback is using the pasteboard, which involves interacting with the user's clipboard.\n\nThe rewrite panel is opened by executing a modifier-only shortcut (Command + Option), which requires careful monitoring of modifier flag changes to avoid triggering unintended keyboard shortcuts. Running the model locally provides the benefit of running writing assistance without sending drafts to a cloud AI service, but it comes with tradeoffs, such as requiring at least 8 GB of RAM and an Apple Silicon Mac running macOS 14 or later.",
  "summary": "I assumed a Mac app that helps you write in any text field would be the easy part. It wasn't. Here's what I learned building DraftKey, an on-device writing assistant for the apps you already use. Reading text across apps means Accessibility There's no public API that says \"give me the text the user is typing in whatever app is in front.\" What macOS does have is the Accessibility API, the same…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}