Moving large files via clipboard on Wayland

Wayland has a clipboard protocol which allows you to copy things between applications (usually through Ctrl-C/Ctrl-V). For a long time, I thought that it works by placing the data you want to copy into memory and then another app requests this in-memory data. This obviously raises the question: how do you copy large files (like screen recordings or movies)?

You may care about this if you write desktop automations. For example, I was recently building a script that would show me pictures and videos that I've taken with the phone in reverse chronological order and allow to quickly copy one of them. This is very useful to quickly send something through email or chat.

It turns out that the clipboard protocol consists of two things:

And there's a generic text/url-list MIME type that is used when you copy something via a desktop file manager. This is why you're able to select multiple files, press Ctrl-C, and then paste them somewhere else.

If you want to achieve the same from a script, you can use wl-copy:


FILE_PATH=some/file.png
echo "file://$FILE_PATH" | wl-copy -t text/uri-list

It is important that the file paths start with file://, because the uri-list also allows you to have a list of http:// links as well. And if you forget the protocol specification - it just won't work.