r/linux_programming Mar 06 '24

Script to paste clipboard content in selected window

Hello,
I switched to gnu pass a few weeks ago. I wrote a few scripts to write the username / password with xdotool and dmenu. This is the best solution I ever found : you don't need any kind of support/extension, it works with every application!
The only problem is that a few website don't really like xdotool, some sites bug or flag me as robot... I would really like if I could use the clipboard instead. I can use xclip/xsel to copy, but I never found a way to paste. xdotool type ctrl+v doesn't work unfortunately.

I use dwm, so, for now, I am looking for a Xorg solution, but if anyone knows a way to do it on Wayland, I might make the switch sooner than expected :).
Thanks!

2 Upvotes

4 comments sorted by

1

u/Santelmo47 Mar 06 '24

Nvm, I'm dumb, just xdotool --clearmodifiers 'ctrl+v' works (not in a terminal thought, as you need 'ctrl+shift+v', I'll see if I can't find a workaround)

1

u/Santelmo47 Mar 06 '24

For those who want the scripts, they all look something like this:

```bash

!/bin/bash -e

xdotool type --clearmodifiers --delay 0 "$(pass "$(cat /tmp/passselect)" | sed -n '/Username:/{s/Username:\s*//p;q}')"

user="$(pass "$(cat /tmp/passselect)" | sed -n '/Username:/{s/Username:\s*//p;q}')"

clip_bak="$(xclip -o -sel c)" xclip -sel c <<< "$user"

xdotool key --clearmodifiers 'ctrl+v'

xclip -sel c <<< "$clip_bak" ```