Reading contents from paste buffer (aka clipboard)

Is there a safe way to read the contents of the clipboard? E.g. if I select text and copy it, can I have Elixir code read that somehow? Or does it have to shell out to system binaries (e.g. pbpaste). Is there any way to normalize that behavior between operating systems, or is that a can of worms?

Thanks for any tips!

1 Like

Technically you can try using wxClipboard. In general shelling out to OS tools is probably the easiest way if you do not want or you cannot use Wx, as it is highly DE-dependant behaviour and Vim clipboard story shows that it is complex matter.

3 Likes

I’ve wrote a library call clipboard_pasta here GitHub - wingyplus/clipboard_pasta. The mechanism is using rust library called copypasta GitHub - alacritty/copypasta: Cross-platform Rust system clipboard library, it support cross platform.

I wrote it under use case that I want to copy datastructure by using elixir pipe syntax (like IO.inspect does). I didnt publish it to the hex yet. If you’re trying and feel it useful, i can help working on and publishing it.

1 Like