Code-aware Copy Text
Copy Text (⇧⌘2) reads text from your screen. When the text looks like code, Frayo keeps the indentation and blank lines, so you can paste it into an editor and run it.
Reading happens on your Mac, with the Vision framework built into macOS. Nothing is uploaded.
How to use it
- Press ⇧⌘2, or choose More Captures › Copy Text.
- Drag over the code.
- The code is on your clipboard. A message says how many lines were copied.
If Frayo decided the text is code, the message has a button: Copy as Code Block. It copies the same text fenced in triple backticks, with the language name, ready for Markdown:
def add(a, b): return a + b
Plain text is copied as plain lines. If the text holds exactly one web link, the message offers Open example.com instead.
What it does
- Indentation. Each line is indented by how far it sits from the left edge. Nested blocks stay nested.
- Blank lines. A big gap between lines becomes one blank line.
- Split lines. When macOS reads one line of code as several pieces, they are joined.
- Lone closers. macOS sometimes skips a line that holds only
}or). If the gap shows a line is missing, Frayo puts the closer back, using the brackets it saw open. - Punctuation. Text is read at 3× size with spelling correction off, so names and symbols are not "fixed".
How it decides it is code
It looks for symbols such as { } ( ) ; =, lines that end in ; { or ,, keywords such as func, def, class or import, and indented lines. Two or more of these signs mean code.
Languages
For the code block tag, Frayo guesses one of: Swift, Python, JavaScript, Go, Rust, Java, JSON, Bash, SQL. If nothing fits, the fence has no language.
Limits
- It is a guess. Short snippets can be missed, and the language can be wrong.
- Indentation is measured, not known. Two-space indentation and unusual alignment can come out a space off.
- A missing closer is only restored when the layout gives it away.
- Read the result before you run it.
Command line
frayo ocr <file> --code gives the same layout. See Command line.
Related: Text and QR codes, Code screenshots.