Skip to content

Instantly share code, notes, and snippets.

@ajitid
Last active December 22, 2023 14:51
Show Gist options
  • Save ajitid/d6df4f5efb3ef5bf7688e9b66ae486e6 to your computer and use it in GitHub Desktop.
Save ajitid/d6df4f5efb3ef5bf7688e9b66ae486e6 to your computer and use it in GitHub Desktop.
Copy and paste pwd (Wayland)

Read readme.md first

It might happen that the input (in which you want to fill the pwd) exist inside a popup and thus opening pkexec could close it. To resolve this we can allow ydotool to be run in w/o sudo password:

  • Execute sudo visudo -f /etc/sudoers.d/my-overrides
  • Paste in this line ajitid ALL=(ALL:ALL) NOPASSWD: /usr/bin/ydotool *
  • Save and exit. Now do sudo -l and you would see an output for ydotool
  • To check if it is working, open a new terminal window and type in sudo /usr/bin/ydotool key 56:1 62:1 62:0 56:0. Upon pressing enter it should either close the window or ask for a confirmation.
  • In clippass script, replace pkexec with sudo

Ref: https://unix.stackexchange.com/a/434918/527120

#!/usr/bin/bash
keyring get system apass | tr -d '\n' | xsel -ib
pkexec ydotool key 29:1 47:1 47:0 29:0
xsel -bc
# or if you're bypassing sudo using visudo, we replace replace `pkexec` with `sudo`, so this becomes:
#!/usr/bin/bash
keyring get system apass | tr -d '\n' | xsel -ib
sudo ydotool key 29:1 47:1 47:0 29:0
xsel -bc
@ajitid
Copy link
Author

ajitid commented May 25, 2022

Explanation of clippass:

  • The first line grabs the password, removes newline at the end and copies it to the clipboard
  • The second line performs ctrl+v
  • The third clears the clipboard

@ajitid
Copy link
Author

ajitid commented May 25, 2022

For X sever, we have https://github.com/jordansissel/xdotool. It might not need sudo. See this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment