Need help with creating a Keyboard Maestro macro to run a Python script

I'm working on a project where I need to create a Keyboard Maestro macro to run a Python script called Main2.py. the Main2.py is inside pycharm project call CorrectSpelling,

the Main2.py python code is very simple : the code i just one line :print(3+7)

the `Main2.py Absolute Path is : /Users/guyatia/PycharmProjects/ColorPaletteGeneratorProject/Main2.py

the CorrectSpelling project Absolute Path is : /Users/guyatia/PycharmProjects/ColorPaletteGeneratorProject

when i run it on my mac terminal i give the output (the number 10) , in the terminal i just type in the first commend : cd /Users/guyatia/PycharmProjects/ColorPaletteGeneratorProject
then in the second commend i type : python Main2.py and then it give me the outcome (the number 10)

Unfortunately, it's not working as expected. When I trigger the macro, nothing seems to happen.

I have confirmed that I have Python installed on my system

Could someone please guide me on how to set up the Keyboard Maestro macro correctly to run the Main2.py script and provide any troubleshooting steps if necessary?

Thank you in advance for your help!

For an Execute shell script action, you will need to include the full path to the python interpreter.


See, for example:

1 Like

please
where i specified the full path to the python interpreter ?
please
here my macro in the screenshot i upload:
in the screenshot you will see the Execute Shell Script commend
and in the Shell Script commend you will see:

in first commend to the path of the project of pycharm, the file math66.py is there (cd /Users/guyatia/PycharmProjects/ColorPaletteGeneratorProject
)

and the second command to activate math66.py :(python math66.py)

please where i give the full path to the python interpreter

Please, I have gone through all the tutorials about executing shell scripts, and I have made numerous attempts to get it to work. However, I am unable to make my macro function properly.

Please, I am not a software engineer, and if you are able and willing, please lend me a hand in getting the macro to work.

correct spelling.kmmacros (1.9 KB)

On my Mac the python interpreter is at /usr/bin/python so your script would look like this on my system:
image

To find the path to python on your Mac, run Terminal and type this command:

which python

the response that comes back is what you should put into your script.

Apologies if this is obvious, but if you're using Python 3 the application will be called python3 instead of python. Its path might be /usr/bin/python3 or /usr/local/bin/python3:

$ which python3
/usr/local/bin/python3

The path depends on how you installed Python (and potentially the version of macOS):

  • Manually, which should result in /usr/local/bin/python3
  • Using Homebrew, which should result in /usr/local/bin/python3
  • With the Xcode developer tools, which should result in /usr/bin/python3 (at least from Ventura onwards; I think Catalina still installs v2)

Best wishes,
Steve

1 Like