Markdown supported · ⌘↵ to post
The promised pasteboard item is a nice way to know when the target app has read the text. One more detail from my own work on typing into other apps: in Safari, Mail and other WebKit views, setting AXValue on a text field returns success, but the text can land in whichever field has the page’s focus, and reading the field back can still report the new value. What held up for me was setting AXFocused, waiting until the app’s focused element really is that field, typing, then reading back. Also, WebKit builds a page’s accessibility tree on the first query, so a window that looks nearly empty is worth reading a second time.
c-wind
The clipboard handoff is a great detail: waiting for the target app to read the promised pasteboard item, then checking the change count before restoring the old contents, avoids overwriting a newer clipboard update. And stripping trailing line breaks is a thoughtful last guard for terminal dictation.