-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatch_copy_threaded.py
More file actions
67 lines (48 loc) · 1.49 KB
/
Copy pathbatch_copy_threaded.py
File metadata and controls
67 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import threading
import pyperclip
current_directory = os.getcwd()
batch_copy_file = current_directory.replace('\\','/') + '/batch_copy.txt'
print(current_directory)
def get_clipboard_data():
data = pyperclip.paste()
return data
def copy_to_clipboard(content):
pyperclip.copy(content)
def clear_clipboard():
pyperclip.copy('')
def batch_copy(seperator):
if seperator == 'space':
seperator = ' '
elif seperator == 'newline':
seperator = '\n'
content_list = []
# Clears the clipboard
clear_clipboard()
# Clears file
open(batch_copy_file, 'w').close()
print("Batch Copy Started")
while not stop_event.isSet():
# Opens file for appending
with open(batch_copy_file, 'a+') as file:
content = get_clipboard_data()
if content:
content_list.append(content)
file.write(content + seperator)
clear_clipboard()
print(content_list)
print("Batch Copy Ended")
with open(batch_copy_file, 'r') as file:
file_content = file.read()
copy_to_clipboard(file_content)
# # Join all blocks together
# content_list = ' '.join(content_list)
# # Insert into clipboard
# copy_to_clipboard(content_list)
def begin_batch_copy(seperator):
stop_event.clear()
thread = threading.Thread(target=batch_copy, args=[seperator])
thread.start()
def end_batch_copy():
stop_event.set()
stop_event = threading.Event()