"There is no one way to put text in every app. There are four ways, and a plan for when each one gives up."
Why a Ladder and Not a Method
macOS has no single reliable "insert this text into the focused field" call that works everywhere. Different apps expose different surfaces, so insertion is a ladder: try the best method that applies, and fall to the next rung when it can't. Each rung trades cleanliness for breadth.
The Four Rungs
1. AX replace cleanest, no clipboard touched
| (only where the app exposes a reliable editable value + range)
v fails ->
2. Pasteboard + Cmd+V broad default for most apps and large text
| (touches the clipboard; needs save/restore etiquette)
v fails / hostile ->
3. Unicode key events synthesize keystrokes, no clipboard side effect
| (slower; good for short text or paste-hostile targets)
v fails ->
4. Clipboard only last resort: copy + notify "paste manually"
Rung 1, AX replace: if the focused element reliably exposes an editable value and selection range, replace through Accessibility — no clipboard touched, cleanest possible. Use it only in apps proven reliable. Rung 2, pasteboard + synthetic Cmd+V: the broad default for large text and most apps; it works almost everywhere but touches the clipboard, so it owes the pasteboard etiquette we'll cover. Rung 3, Unicode key events: synthesize the characters via CGEvent — no pasteboard side effect, but slower; good for short text or paste-hostile targets. Rung 4, clipboard-only: when nothing else applies, copy the text and tell the user to paste it.
Degrade, Don't Fail
The point of the ladder is that insertion never simply fails — it degrades. Even the worst case (clipboard + notify) leaves the user one keystroke from their text, with a clear message about what happened. Compare that to a single-method design: pick AX-only and you break in every app that doesn't expose it; pick paste-only and you're stuck when a target rejects paste. The ladder means there's always a rung that works, and the user always ends up with their words.