Selection Engine & Clipboard Safety
Architecture & InternalsSelection Engine & Clipboard Safety

Selection Engine & Clipboard Safety

3-tier selection extraction cascade, AX element reading, and zero-pollution clipboard snapshots.

Selection Retrieval Cascade

OpenClip routes selection extraction based on application type:

Application CategoryRetrieval CascadeGuarantees
Native Apple Apps (Notes, TextEdit, Pages).axTextControl0ms direct AX read; terminates immediately if no text is selected.
Web Browsers (Safari, Chrome, Arc, Firefox).axWebArea → .browserScript → .keyboardCopyPolls WebKit DOM markers with settle retries.
Terminals & Shells.menuCopyAX Edit ▸ Copy walk with denyPaste: true.
Electron & 3rd-Party Apps.axTextControl → .keyboardCopySynthetic ⌘C with instant clipboard restoration.

Direct Accessibility (AX) Extraction

To prevent UI hangs, AX inspection runs on a concurrent background queue (com.openclip.ax-inspect) gated by an AXSlot actor (at most 1 blocking AX worker) and raced against a 0.5-second timeout watchdog (Constants.axReadTimeout).

Zero-Pollution Clipboard Snapshot & Restore

When fallback synthetic copy is needed:

  • Verbatim Multi-Type Snapshot: Clones all pasteboard representations across all data types.
  • 2ms Polling Loop: Listens for pasteboard.changeCount changes with a 0.25s timeout (0.4s for Safari).
  • Immediate Restoration: Replaces original clipboard items immediately upon reading the text.
  • Transient Marker Tags: Attaches org.nspasteboard.TransientType and org.nspasteboard.AutoGeneratedType tags to prevent 3rd-party clipboard managers from logging intermediate copy cycles.