Skip to content

Commit 7826c48

Browse files
Create Copy2Clip file
1 parent e0f9b7f commit 7826c48

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Copy2Clip/Copy2Clip.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import sys
3+
import platform
4+
import subprocess
5+
6+
# Seeing if the file exists
7+
if os.path.exists(sys.argv[1]):
8+
f = open(sys.argv[1], "r")
9+
f_contents = f.read()
10+
f.close()
11+
else:
12+
print("Usage: copy2clip <file_name>")
13+
exit(1)
14+
15+
whatos = platform.system()
16+
17+
if whatos == "Darwin":
18+
subprocess.run("pbcopy", universal_newlines=True, input=f_contents)
19+
print("success: copied to clipboard")
20+
elif whatos == "Windows":
21+
subprocess.run("clip", universal_newlines=True, input=f_contents)
22+
print("success: copied to clipboard")
23+
else:
24+
print("failed: clipboard not supported")
25+

0 commit comments

Comments
 (0)