Copy code straight out of a video call
Drag over code on a shared screen. Paste it, indented, into your editor.
Someone shares their screen and says "just use this snippet". The snippet is on a slide, in a stream or in a recording. You cannot select it. You squint, retype it, and miss a brace.
Normal text recognition makes it only a little better. It reads the words and loses the layout. You get code with every line flush left, which in Python is no code at all.
Copy Text, but it knows about code
Press ⌥⇧2 and drag over the code. Frayo reads it on your Mac, then looks at where each line sits.
- Indentation is rebuilt from how far each line is from the left edge.
- Blank lines stay, so functions are still separated.
- Split lines are joined. Text recognition sometimes cuts one line into pieces.
- Missing closers come back. Recognition often drops a line that is just
}. When the gap shows a line is missing, Frayo puts the bracket back, based on the ones that were open. - Punctuation is left alone. Spell-correction is off, so
fooBardoes not become "foo bar".
The result goes to your clipboard. A message says how many lines, with a button: Copy as Code Block. That copies the same code fenced in triple backticks and tagged with a guessed language (Swift, Python, JavaScript, Go, Rust, Java, JSON, Bash or SQL), ready for a chat or a pull request.
How it knows it is code
It does not ask you. It looks for the signs: lots of { } ( ) ; =, lines ending in ; or {, keywords like def and import, and indented lines. With two or more signs it treats the text as code. Otherwise you get plain lines, as before.
It is a guess
We want to be straight about this.
- Text on a compressed video is soft. Small or blurry code gives worse results. Pause the video and zoom in if you can.
- Indentation is measured from pixels, not known. Four- and eight-space code comes out well. Two-space code and odd alignment can be off by a space.
- A restored closer is a guess from the layout.
- A short snippet may not be recognised as code, and the language tag can be wrong.
Always run it, or at least read it, before you trust it. It saves you the retyping, not the review.
Everything stays on your Mac
The image is read with the Vision framework in macOS. Nothing is uploaded, and the image is thrown away as soon as the text is read.
Two more things
Once you have the code, Tools → Code Screenshot from Clipboard turns it into a clean image with a theme, line numbers and a window frame, for a slide or a post.
And if you want the text from a file or a script, frayo ocr shot.png --code does the same from the command line.