Skip to content

TIL: OSC 52

Erica Pisani
Erica Pisani
— 1 min read
TIL: OSC 52

I’m working on setting up a mini PC to serve as my homelab server instead of my MacBook (more details to come in a future post) and I’ve configured it so I can ssh into it from anywhere.

However, there’s been a few times where I’ve needed to copy file contents from the server to my laptop’s clipboard and I couldn’t use “cmd+c” to do this.

Enter OSC 52. It’s an escape sequence that allows you to copy text from anywhere from the terminal because it tells your terminal that the string it carries must be copied to the system clipboard.

Here's an example of what it looks like:

"\033]52;c;%s\007" "$(base64 | tr -d '\n')"

Source: https://jvns.ca/til/vim-osc52/

Julia Evans has a short TIL about this escape sequence as well, and even shares a small script that you can save and call pbcopy, so you don’t even need to think about it if you’re used to working on macOS.

til

Comments