From 3cd6e5c426f801159ea9a85b2463687b8a69c545 Mon Sep 17 00:00:00 2001 From: Siddhesh Bhupendra Kuakde <65951872+SiddheshKukade@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:34:27 +0530 Subject: [PATCH] Create clipboard.py --- scripts/Copy to clipboard/clipboard.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/Copy to clipboard/clipboard.py diff --git a/scripts/Copy to clipboard/clipboard.py b/scripts/Copy to clipboard/clipboard.py new file mode 100644 index 0000000..1742b1e --- /dev/null +++ b/scripts/Copy to clipboard/clipboard.py @@ -0,0 +1,29 @@ +import os +import sys +import platform +import subprocess + +# Seeing if the file exists +if os.path.exists(sys.argv[1]): + # Open Only if the file exists on the computer + f = open(sys.argv[1], "r") + # Storing the Content of the file in the f_contents variable + f_contents = f.read() + # closing the opened file + f.close() +else: + # If the file Doesn't Exists + print("File Not found : copy2clip ") + exit(1) +# Storing the current OS version +whatos = platform.system() +# If Darwin or Ubuntu +if whatos == "Darwin": + subprocess.run("pbcopy", universal_newlines=True, input=f_contents) + print("success: copied to clipboard") +# If Windows +elif whatos == "Windows": + subprocess.run("clip", universal_newlines=True, input=f_contents) + print("success: copied to clipboard") +else: + print("failed: clipboard not supported")