From 5eb09d9b8573e88ee65d83553e14cba66d1bbefd Mon Sep 17 00:00:00 2001 From: cswimr Date: Fri, 22 Nov 2024 10:04:55 -0500 Subject: [PATCH] use `pyperclip` for clipboard manipulation --- scripts/spectacle-screenshot.py | 2 +- scripts/zipline.py | 24 +++--------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/scripts/spectacle-screenshot.py b/scripts/spectacle-screenshot.py index 85fd180..9673761 100755 --- a/scripts/spectacle-screenshot.py +++ b/scripts/spectacle-screenshot.py @@ -1,5 +1,5 @@ #! /usr/bin/env nix-shell -#! nix-shell -i python -p python312 +#! nix-shell -i python -p python312 libnotify import argparse import os diff --git a/scripts/zipline.py b/scripts/zipline.py index cae12c7..897ea04 100755 --- a/scripts/zipline.py +++ b/scripts/zipline.py @@ -1,34 +1,16 @@ #! /usr/bin/env nix-shell -#! nix-shell -i python -p python312 python312Packages.tkinter python312Packages.requests libnotify +#! nix-shell -i python -p python312 python312Packages.pyperclip python312Packages.requests libnotify import argparse import mimetypes import os -import subprocess from pathlib import Path from shutil import which -from tkinter import Tk from typing import Any import requests # type: ignore from common.common import does_desktop_entry_exist, notify, read_secret_file - - -def copy_to_clipboard(text: str) -> None: - if which("xclip"): - subprocess.run( - ["xclip", "-selection", "clipboard", "-t", "text/plain", "-i"], - input=text.encode(), - ) - elif which("wl-copy"): - subprocess.run(["wl-copy", "--type", "text/plain"], input=text.encode()) - else: - root = Tk() - root.withdraw() - root.clipboard_clear() - root.clipboard_append(text) - root.update() - root.destroy() +from pyperclip import copy def zipline( @@ -72,7 +54,7 @@ def zipline( link = response_data.get("files", [None])[0] if link: - copy_to_clipboard(text=link) + copy(text=link) print(f"Link copied to clipboard: {link}") if use_send_notify: