On 29/09/26 at 16:33, Greg Wooledge wrote:
I predict you will have follow-up questions. I predict that one of
them will be "how do I write it so that it takes the payload either
from stdin*or* from the argument list?" So, here's a variant that
looks for arguments, and uses those if present, and otherwise uses
stdin:
toclip() {
local payload
if (($#)); then
payload="$*"
else
payload=$(cat)
fi
qdbus6 org.kde.klipper /klipper \
org.kde.klipper.klipper.setClipboardContents "$payload"
}
Just a follow-up question: "Can superuser (root) and not privileged user
run both this function?" I've solved so:
toclip() {
local payload
if (($#)); then
payload="$*"
else
payload=$(cat)
fi
setpriv --reuid "$(id -u YourUser)" \
env XDG_RUNTIME_DIR=/run/user/$(id -u YourUser) \
qdbus6 org.kde.klipper /klipper \
org.kde.klipper.klipper.setClipboardContents "$payload"
}
Replace YourUser with your username and when you become superuser you'll
be able to send text to the clipboard.
Out of curiosity I'd like to know if this function works also under
Wayland (kwin_wayland). Does anyone have a KDE desktop running a Wayland
session to test it?
Thanks, kind regards.
--
Franco Martelli