Skip to content

Commit 7df8fcd

Browse files
authored
Merge pull request #360 from CodeReaper-10/copy-to-clip
Copy to clipboard
2 parents 8b4c1ee + 96e184c commit 7df8fcd

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ Once you are done working on your script edit this `README.md` file and add the
9898
71| Water Reminder | Reminds you to drink water every 2 hours | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Water%20Reminder)
9999
72| QR and Barcode Scanner | Scans both QR Codes and Barcodes | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/QR%20and%20Barcode%20Scanner) |
100100
73| PDF-Delete-Pages | Deletes pages from PDF as entered by the user | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/PDF-Delete-Pages) |
101+
74| Copy to clipboard | Copies contents form a text file to your clipboard | [Find me Here](https://github.com/GDSC-RCCIIT/General-Purpose-Scripts/tree/main/scripts/Copy%20to%20clipboard) |
101102
### Good Luck and don't forget to have fun with Open Source 🚀
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## How to run
2+
3+
1. Clone the repository
4+
```
5+
git clone [email protected]:GDSC-RCCIIT/General-Purpose-Scripts.git
6+
```
7+
2. Install the script requirements
8+
```
9+
pip install -r requirements.txt
10+
```
11+
3. Navigate to `Copy to clipboard` directory
12+
```
13+
cd General-Purpose-Scripts/scripts/Copy to clipboard
14+
```
15+
4. Run the script to copy text from the desired file to your clipboard
16+
```
17+
python clipboard.py <file_name>
18+
```
19+
### Note
20+
Replace <file_name> with the name of the file present in the same directory as the script or replace it with the path of the file.
21+
For Linux users, install [xclip](https://linoxide.com/copy-paste-commands-output-xclip-linux/) in your system before running the script.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import sys
3+
import platform
4+
import subprocess
5+
import pyperclip
6+
7+
# Seeing if the file exists
8+
if os.path.exists(sys.argv[1]):
9+
f = open(sys.argv[1], "r")
10+
f_contents = f.read()
11+
f.close()
12+
else:
13+
print(
14+
"Usage: python clipboard.py file_name\n OR\n python clipboard.py 'path_of_the_file'"
15+
)
16+
exit(1)
17+
18+
whatos = platform.system()
19+
20+
if whatos == "Darwin":
21+
subprocess.run("pbcopy", universal_newlines=True, input=f_contents)
22+
print("Success! Copied to clipboard.")
23+
elif whatos == "Linux":
24+
pyperclip.copy(f_contents)
25+
print("Success! Copied to clipboard.")
26+
elif whatos == "Windows":
27+
subprocess.run("clip", universal_newlines=True, input=f_contents)
28+
print("Success! Copied to clipboard.")
29+
else:
30+
print("Failed! Clipboard not supported.")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyperclip==1.8.2

0 commit comments

Comments
 (0)