Search code examples
pythonclipboardshelve

Multiclipboard Automate the boring Stuff


I have some difficulties to run this program. You can see how to run it on Windows. But how does it work for Mac? For instance, python3 mcb.py save spam, when I type it into the console in Spyder it gives me this error message

python3 mcb.py spam
  File "<ipython-input-476-bd7c517010f3>", line 1
    python3 mcb.py spam
              ^
SyntaxError: invalid syntax

When I just run the program without putting any command in it creates a db file. Can you give me some instructions on how to run this program properly

#! python3
# mcb.pyw - create a multiclipboard tool
# Usage: py.exe mcb.pyw save <keyword> - Saves clipboard to keyword.
#        py.exe mcb.pyw <keyword> - Loads keyword to clipboard.
#        py.exe mcb.pyw list - loads all keywords to clipboard.


import shelve, pyperclip, sys

#open the shelve
mcbShelf = shelve.open('mcb')

#save clipboard content
if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':
    mcbShelf[sys.argv[2]] = pyperclip.paste()
#either copy keys to clipboard or copy value of a key
elif len(sys.argv) == 2:
    if sys.argv[1].lower() == 'list':
       pyperclip.copy(str(list(mcbShelf.keys())))
    elif sys.argv[1] in mcbShelf:
       pyperclip.copy(mcbShelf[sys.argv[1]])

#close out the shelve
mcbShelf.close()

Solution

  • You are trying to run

    python3 mcb.py spam
    

    from within Python (via Spyder).

    That command is meant to be run in a regular operating system terminal.

    Try opening up Terminal, cding to the directory that holds mcb.py, and running the command there. Alternatively, install a system-level terminal in Spyder and run it there.