-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcb.pyw
56 lines (48 loc) · 2 KB
/
mcb.pyw
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
# This is a task from Chapter 9, called 'Extending the Multi-Clipboard'
# below is the original code, it's under comments, because it was in a book
# mcb.pyw - Saves and loads pieces of text to the clipboard.
# Usage: python mcb.pyw save <keyword> - Saves clipboard to keyword.
# python mcb.pyw <keyword> - Loads keyword to clipboard.
# python mcb.pyw list - Loads all keywords to clipboard.
# this should be typed in IDEs terminal or command prompt if the bat file is created
# import shelve, pyperclip, sys
#
# mcbShelf = shelve.open('mcb')
#
# if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':
# # Save clipboard to keyword.
# mcbShelf[sys.argv[2]] = pyperclip.paste()
# elif len(sys.argv) == 2:
# if sys.argv[1].lower() == 'list':
# # Copy list of keywords to clipboard.
# pyperclip.copy(str(list(mcbShelf.keys())))
# elif sys.argv[1] in mcbShelf:
# # Load the keyword to the clipboard.
# pyperclip.copy(mcbShelf[sys.argv[1]])
#
# mcbShelf.close()
# Extending the Multi-Clipboard
# Extend the multi-clipboard program in this chapter
# so that it has a delete <keyword> command line argument
# that will delete a keyword from the shelf.
# Then add a delete command line argument that will delete all keywords.
import shelve, pyperclip, sys
mcbShelf = shelve.open('mcb')
if len(sys.argv) == 3:
if sys.argv[1].lower() == 'save':
# Save clipboard to keyword.
mcbShelf[sys.argv[2]] = pyperclip.paste()
elif sys.argv[1].lower() == 'del':
# delete keyword from the clipboard
del mcbShelf[sys.argv[2]]
elif len(sys.argv) == 2:
if sys.argv[1].lower() == 'list':
# Copy list of keywords to clipboard.
pyperclip.copy(str(list(mcbShelf.keys())))
elif sys.argv[1] in mcbShelf:
# Load the keyword to the clipboard.
pyperclip.copy(mcbShelf[sys.argv[1]])
elif sys.argv[1].lower() == 'delall':
# delete all keywords
mcbShelf.clear()
mcbShelf.close()