Create clipboard.py

This commit is contained in:
Siddhesh Bhupendra Kuakde 2022-10-12 19:34:27 +05:30 committed by GitHub
parent f78c514631
commit 3cd6e5c426
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 <file_name>")
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")