57 lines
2.1 KiB
Bash
Executable File
57 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ollie:parallel read
|
|
# ollie:prompt
|
|
# ## gui_clipboard
|
|
#
|
|
# Read/write KDE clipboard via Klipper.
|
|
#
|
|
# **Args**: `[action]` or `[action, text]`
|
|
# - Actions: `get`, `set`, `history`
|
|
#
|
|
# ```
|
|
# call_tool: calls=[{tool: "gui_clipboard", args: ["get"]}]
|
|
# call_tool: calls=[{tool: "gui_clipboard", args: ["set", "copied text"]}]
|
|
# ```
|
|
# ollie:end
|
|
set -euo pipefail
|
|
|
|
SERVICE="org.kde.klipper"
|
|
PATH_OBJ="/klipper"
|
|
IFACE="org.kde.klipper.klipper"
|
|
|
|
cmd="${1:-get}"
|
|
|
|
case "$cmd" in
|
|
get)
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.getClipboardContents" | \
|
|
sed "s/^('//;s/')$//;s/\\\\n/\n/g"
|
|
;;
|
|
set)
|
|
if [ $# -lt 2 ]; then echo '{"schema": {"type": "array", "items": [{"name": "action", "type": "string", "description": "get|set|history|clear", "required": true}, {"name": "text", "type": "string", "description": "Text to set (for set action)", "required": false}], "examples": [["get"], ["set", "hello world"], ["history"], ["clear"]]}}'; exit 1; fi
|
|
text="${2}"
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.setClipboardContents" "$text" >/dev/null
|
|
echo "OK: clipboard set"
|
|
;;
|
|
history)
|
|
index="${2:-0}"
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.getClipboardHistoryItem" "$index" | \
|
|
sed "s/^('//;s/')$//;s/\\\\n/\n/g"
|
|
;;
|
|
clear)
|
|
gdbus call --session --dest "$SERVICE" \
|
|
--object-path "$PATH_OBJ" \
|
|
--method "$IFACE.clearClipboardHistory" >/dev/null
|
|
echo "OK: clipboard history cleared"
|
|
;;
|
|
*)
|
|
echo '{"schema": {"type": "array", "items": [{"name": "action", "type": "string", "description": "get|set|history|clear", "required": true}, {"name": "text", "type": "string", "description": "Text to set (for set action)", "required": false}], "examples": [["get"], ["set", "hello world"], ["history"], ["clear"]]}}' >&2
|
|
exit 1
|
|
;;
|
|
esac
|