#!/usr/bin/python3 # # Crostini Clip -- push argv[1] to the system clipboard # # Use xterm control sequences, instead of xclip's xwindows mechanism (which # seems broken on recent Crostini). See info below. # import sys import base64 # The content must be base64 encoded. e = base64.b64encode(bytes(sys.argv[1], 'latin-1')) a = e.decode('ascii') # Embed that within an ESC coded sequence to the xterm # https://www.xfree86.org/current/ctlseqs.html # "ESC OSC Ps ; Pt ST" # OSC = Operating System Command = 0x9d = "]" # Ps = "52" = Manipulate selection data (clipboard) # Pt = "Pc ; Pd" # Pc = "c" (for cut buffer) # Pd = base64-encrypted value for buffer # ST = String Terminator = 0x9c = "\" ### note: there is an ESC between Pd and ST. Hunh? Meh. It still works. print(f'\033]52;c;{a}\033\\')