The Autodidacts

Exploring the universe from the inside out

Paste clipboard contents in places where you can’t paste

Use AutoKey send_keys() to put clipboard content places where it can't normally be put

Note: this post is part of #100DaysToOffload, a challenge to publish 100 posts in 365 days. These posts are generally shorter and less polished than our normal posts; expect typos and unfiltered thoughts! View more posts in this series.

Today I was trying to run an AppImage in a firejail sandbox, to debug the issue that is currently blocking my KOReader Wallabag plugin patch.

In the process, I had to paste API keys that were too long to reliably type, and I couldn’t paste into the AppImage with the normal methods.

It turns out you can (duh) paste with a long press, just like on an e-reader. But this is so wildly unintuitive on desktop that I didn’t think of it at the time.

Instead, I wrote a two-line Python AutoKey script, bound to a keybinding (Ctrl+Alt+Shift+Super+k, because all the good keybindings are already taken).

cb = clipboard.get_clipboard()
keyboard.send_keys(cb)

This gets the current clipboard content, and emits it as if it was being typed. Simple, and effective.

I’ve run into places where I can type but can’t paste before, so although there was a simpler solution in this particular case, the snippet might be useful in other circumstances.

Sign up for updates

Join the newsletter for curious and thoughtful people.
No Thanks

Great! Check your inbox and click the link to confirm your subscription.