Concept from my reply in termux/termux-api#452 (comment). It spawns a Termux:Float instance to temporarily gain foreground activity, allowing Termux to read the system clipboard.
This is currently the most efficient workaround, according to Benjamin-Loison/termux-api#32.
Check out Benjamin_Loison/ADB_clipboard !
Save the clipboard-get.sh into your device. Chmod it and run it with ./clipboard-get.sh.
If you're SSH'ing into Termux from a different machine, use ssh termux ./clipboard-get.sh. Or if the script isn't installed, use:
ssh termux bash << 'EOF'
# ... clipboard-get.sh body ...
EOFThe script takes about 1-3 seconds to complete.
For better consistency, you may need to fine-tune the sleep time in line 6, depending on your system performance.