0

INSTEAD OF COMPLETELY DELETING THIS, I'M MAKING THIS EDIT SO PEOPLE WHO FIND THIS ARE ABLE TO FIND THE BEST SOLUTION.

GO TO How to run a shell script in OS X by double-clicking?

While using Python, I would like to be able to run a script without having to open or type into Terminal every time. For example, instead of going into Terminal and typing:

python <script-name>.py

or even

./script-name.py

I would like to simply be able to click on an application or open a file that will automatically run the Terminal commands without actually having to open Terminal myself (or at least have Terminal open in the background) so that others (like my mother) can use this easily.

Is anyone able to point me in a direction or help me out in figuring out if this is possible? Please do not hesitate to ask me questions. I appreciate any help at all. Thank you in advance!

  • 2
    which os are you using? – Nihal Jun 11 '18 at 07:03
  • 1
    make executable of your script. – Nihal Jun 11 '18 at 07:04
  • 1
    Possibly duplicate: https://stackoverflow.com/a/29710607/240443 – Amadan Jun 11 '18 at 07:10
  • 1
    The nominated duplicate mentions "shell script" but the precise type of script is unimportant. – tripleee Jun 11 '18 at 07:13
  • On the page mentioned by Amadan, someone suggested: "create a macOS application with Automator using the Run Shell Script action". – ThomasW Jun 11 '18 at 07:13
  • 1
    Yes, depends whether you want the Terminal to open at all, or not. It's easier to just rename the script (and set it executable, and have proper shebang); but if you don't want the Terminal screen and don't mind a second file to invoke your script, Automator is probably the best option. – Amadan Jun 11 '18 at 07:14
  • Thank you all, Amadan pointed me in the perfect direction. – Jacob Polacek Jun 12 '18 at 17:01

2 Answers2

1

Add shebang at the beginning of the python script

#!/usr/bin/env python

Or For python 3

#!/usr/bin/env python3

And then change the file permission to make it self executable.

chmod +x script-name.py
MaNKuR
  • 2,578
  • 1
  • 19
  • 31
0

You can use pycharm IDE ,a cross platform IDE for python works on windows,linux macos ,you can edit execute,develop python scripts https://www.jetbrains.com/pycharm/

ramzi tannous
  • 93
  • 2
  • 5