Mac OS X – Link/shortcut to a python script

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.

On Windows
I would create a shortcut and point it at “python c:/scripts/” 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:

  1. Create your script file
  2. Write your script
  3. Make it executable

Here’s how to do it all in Terminal:

  1. Open up Terminal
  2. Navigate to where you want your shortcut to be.
  3. Type “touch open_script”. This creates a file called “open_script”.
  4. Type “nano open_script”. This will open up the Nano text editor.
  5. Write your script. Mine looks like this: Note: Your first line MUST be the same as mine.
    cd /Applications/basic_scripts

  6. When you are done save your file and exit Nano by doing: CTRL-O , CTRL-X
  7. 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.


About Mr Chimp

I make music, draw pictures, browse the internet, programme, and make sweet, sweet cups of tea until the early hours.
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

2 Responses to Mac OS X – Link/shortcut to a python script

  1. R says:

    Thanks for the tip :0)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s