Files
sshyp/lib/clipclear.py
T
RandyTheSilly a487bd561a Fix clipboard contents sometimes failing to clear
Former-commit-id: 8ecbbb6199864fda973e47605a10d737318f3993
Former-commit-id: eb625eded3f9518967ee9fa06201311e8571e394
2023-10-20 00:32:29 -04:00

28 lines
917 B
Python
Executable File

#!/usr/bin/env python3
from hashlib import sha512
from subprocess import PIPE, run
from sys import argv
from time import sleep
# set period of time to wait before attempting to clear clipboard
sleep(30)
# store a hash of the current clipboard contents for later comparison
_hash_paste = sha512()
_hash_paste.update(run('wl-paste', stdout=PIPE).stdout.strip())
# if the supplied hash matches the hash of the current clipboard contents, clear the clipboard
if argv[1] == _hash_paste.hexdigest():
if argv[2] == 'wsl':
run(('powershell.exe', '-c', 'Set-Clipboard'))
elif argv[2] == 'wayland':
run(('wl-copy', '-c'))
elif argv[2] == 'haiku':
run(('clipboard', '-r'))
elif argv[2] == 'mac':
run('pbcopy', input=b'')
elif argv[2] == 'termux':
run(("termux-clipboard-set", "''"))
elif argv[2] == 'x11':
run(('xclip', '-i', '/dev/null', '-sel', 'c'))