I have written an interactive script in Python. I want to be able to double-click .py files and have them open in IDLE for editing. I also want to be able to run the Python file in Terminal without having to open Terminal manually, navigate in Terminal to the script and then execute it. I just want to double click on something and everything be ready. This is quite simple to do but being used to windows as I am it took me a little while to figure out how to do it.
I would create a shortcut and point it at “python c:/scripts/myscript.py” that should do the job.
On Mac OS X
As far as I can see Macs don’t really use links/shortcuts. So we’ll do it a different way – create a small executable (i.e. will just run when you double click it) Bash script that will open our Python script for us.
We’ll name this script open_script. You can call it what you like.
The basic steps are:
- Create your script file
- Write your script
- Make it executable
Here’s how to do it all in Terminal:
- Open up Terminal
- Navigate to where you want your shortcut to be.
- Type “touch open_script”. This creates a file called “open_script”.
- Type “nano open_script”. This will open up the Nano text editor.
- Write your script. Mine looks like this: Note: Your first line MUST be the same as mine.
- When you are done save your file and exit Nano by doing: CTRL-O , CTRL-X
- Type “chmod 755 open_script” – this will make your script executable.
You can now double click your shortcut.
You don’t have to do it all in terminal. You could create your script in any text editor you like, then just skip to step 7 to make it executable.