The awkward case for a Mac selection toolbar is a footnote in a scan. In a browser, the user can drag across a sentence and an app may expose the string through Accessibility. In a scanned PDF, the same drag may yield a rectangle of pixels. You want the toolbar to feel familiar in both cases, while keeping that rectangle on the Mac and making the translation request a deliberate choice.
Lassoly’s selection toolbar and browser playground illustrate that interaction. Its Mac client builds on GPL-3.0 Easydict for selection capture and on-device OCR. The design below is a reference architecture for anyone building a similar tool. The Swift example shows the OCR step. Easydict source and license.
Let selection create a candidate
Check Accessibility permission during setup and explain the feature that needs it. Use the focused Accessibility element to ask for the selected string. When the application exposes a selection range and useful bounds, you can position the toolbar around it. If the bounds are missing, a pointer-relative fallback is often better than a popup anchored to the wrong display. Treat an unsupported selection as a regular outcome, including PDF viewers with custom text layers and fields that deliberately hide their contents.
Keep the candidate and its screen position in memory. A new selection replaces it. A focus change dismisses it. The toolbar may briefly debounce selection events to avoid flicker while someone drags. Give the selection observer access to UI state so it can decide what to show, and reserve the provider client for the action dispatcher.
That separation fixes a common race. A user highlights one sentence, changes windows, and presses a shortcut while the previous toolbar is still disappearing. A toolbar button should carry the generation of the candidate that drew it. For a global shortcut, resolve the intent against the current focus. Either way, reject a stale candidate before assembling a network request.
Give pixels a separate path
Lassoly’s Mac screenshot OCR workflow uses Option–S (⌥S). Pause a video, open a scanned PDF, or find the label in an image and drag a rectangle around it. Screen Recording permission is required for capture. Tools that only act on selectable text can leave that permission off.
Once a capture succeeds, feed the cropped bitmap to Apple Vision on the device. This helper illustrates recognition of a single crop. Run it away from the UI thread and preserve the recognized lines so the caller can decide how to display them. Apple Vision text recognition documentation.
import CoreGraphics import Vision func recognizeLines(in crop: CGImage) throws -> [String] { let request = VNRecognizeTextRequest() request.recognitionLevel = .accurate try VNImageRequestHandler(cgImage: crop, options: [:]).perform([request]) return (request.results ?? []).compactMap { $0.topCandidates(1).first?.string } } Put image buffers on the capture side of the design and release them when recognition finishes. Define how the overlay’s coordinates map to image pixels before doing any OCR work. Test on a Retina display and an external monitor with a different scale factor. A crop that lands a few lines too high can include precisely the text the user meant to exclude.
A Vision result is a best guess. Narrow crops help with multi-column PDFs, and pausing a moving subtitle can improve legibility. For a code sample or part number, an OCR substitution such as O for 0 can change the answer downstream. Start your test set with receipts, mixed scripts, and a two-column scan. Use examples where reading a line from the wrong column would change the meaning.
Build the request after a user action
Route each action button, translation shortcut, or submitted follow-up through a single dispatcher. The dispatcher receives only the fields needed by the chosen action. A minimal first-turn payload might carry an action identifier and the selected or recognized text. A follow-up can also carry the conversation context needed by the provider. A dedicated request type makes it harder to accidentally serialize app names, window titles, browser URLs, clipboard contents, or image buffers that happen to be available elsewhere in the app.
Lassoly’s documented selection flow sends content after an explicit action. In its screenshot translation flow, completing the capture triggers Vision recognition locally. The recognized text can then go to Youdao, an AI provider, or both, according to settings. Make that behavior clear near the shortcut or capture overlay. In a tool that offers a separate OCR-only action, it helps to name the actions distinctly so a user can predict which one sends text.
Allow the dispatcher to choose a provider after the boundary check. Lassoly includes account-based AI access and offers optional DeepSeek bring-your-own-key (BYOK) for selection actions. DeepSeek bills those requests directly and they use zero Lassoly credits. The text still goes to a remote provider. A key changes who bills the request and which service processes it.
Test the boundary from the outside
Replace your transport with a recorder. Drag through several sentences, move the pointer, switch windows, and modify the clipboard. Assert that the selection flow produces zero provider requests. Click a toolbar action and assert that exactly one request contains the expected string. Give the window title, URL and clipboard distinct test markers, then check the serialized request and diagnostic events for those markers. Keep unrelated app activity such as sign-in outside the recorder’s selection-request assertions.
Then simulate a screenshot drag that the user cancels and a completed crop that yields no text. Neither case needs a translation call. For a successful capture, inspect the exact payload and confirm that the image stays in the local OCR path. Repeat with delayed OCR completing after the user dismisses the overlay. Cancel or invalidate obsolete work so a late result cannot translate on its own.
Finally, drive the UI against a real browser, PDF viewer, editor, and a field that intentionally exposes no selection. The useful acceptance test is temporal. You should be able to point to the user event that authorized every outgoing text request and explain which text it carried.
Note: Portions of the code examples, formatting, and editorial drafting were assisted by AI tools and reviewed/verified by the author.


