1

Following the book 'Automate the boring stuff with Python' I wrote a Python script called mclip.py.

#! python3
# mclip.py - A multi-clipboard program.

TEXT = {'agree': """Yes, I agree. That sounds fine to me.""",
'busy': """Sorry, can we do this later this week or next week?""", 'upsell': """Would you consider making this a monthly donation?"""}

import sys, pyperclip 

if len(sys.argv) < 2:
    print('Usage: py mclip.py [keyphrase] - copy phrase text') 
    sys.exit()

keyphrase = sys.argv[1] # first command line arg is the keyphrase

if keyphrase in TEXT:
    pyperclip.copy(TEXT[keyphrase])
    print('Text for ' + keyphrase + ' copied to clipboard.')
else:
    print('There is no text for ' + keyphrase)

When I run this in visual studio code I get:

XXX@XXXs-MacBook-Pro Python Projects % /usr/local/bin/python3 "/Users/XXX/Desktop/Python Projects/mclip.py"
Usage: py mclip.py [keyphrase] - copy phrase text

But following the instructions of the book when trying to run the script from the terminal typing python3 mclip.py $busy I get:

XXX@XXXs-MacBook-Pro ~ % python3 mclip.py 
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'mclip.py': [Errno 2] No such file or directory

It should copy the value of the specific keyword but is not doing so. I am not sure what is causing this problem. Help is much appreciated!

Maybe there could be a problem with the Path VSC is set up with but I am not sure.

4
  • Is this a question about how to run a script in python, or how your script behaves once it is running? Commented May 30, 2020 at 11:23
  • I try to run a script from the terminal. But it is not working as it should. Running the script from VSC is not working as it should as well. Commented May 30, 2020 at 12:32
  • Can you explain the difference in the output you are seeing? Commented May 30, 2020 at 12:34
  • I don't quite understand your question. I posted the output in the description of my question (If I run it directly from VSC or the terminal). Commented May 30, 2020 at 12:35

1 Answer 1

1

I managed to solve the Problem by myself and wanted to say here that no one has to bother finding a solution for me or in case my solution may be helpful for other people around here. My Mistakes were:

  1. Trying to run the program without an argument. When calling the program I need to call it with an argument: python3 mclip.py busy
  2. Saving my scripts in an iCloud folder. Apparently it needs to be saved local.

These are all the changes I made and now it's running smoothly.

Thanks for the help anyone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.